ios UIView中的UIButton不能点击按钮

.h文件

import

@interface HUPrompt : UIView

.m文件

import "HUPrompt.h"

import "UIView+Layout.h"

@implementation HUPrompt

UIImageView *backView = [[UIImageView alloc] init];

backView.frame = self.frame;
backView.image = _backImage;
[self addSubview:backView];
self.button = [[UIButton alloc] initWithFrame:CGRectMake(0, label.bottom+23, 74, 32)];

self.button.isPercentSize = YES;
self.button.backgroundColor = Btn_COLOR;
[self.button setTitle:@"知道了" forState:UIControlStateNormal];
[self.button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.button addTarget:self action:@selector(cancle1) forControlEvents:UIControlEventTouchUpInside];
self.button.titleLabel.font = TextSize;
self.button.layer.cornerRadius = 15;
self.button.layer.masksToBounds = YES;
[backView addSubview:self.button];
self.button.isHorizontalCenter = YES;
-(void)cancle1{

NSLog(@"sdfdsfds");
}

然后我在uiviewController调用 能显示 frame是传进来了的 但是不能点击 没触发事件 我想是不是uiview中不能用addTarget这个方法啊 求解答

你的button是加在imageview上面,加在self上面试试看。

忘了说,把交互打开。

[backView addSubview:self.button];改成[self addSubview:self.button];试试

HUPrompt : UIView 本身就是一个view,你用覆盖一个backView,完全是多余的,你发现了没

把交互打开,user interface