UIView *background = [[UIView alloc] initWithFrame:self.view.bounds];
background.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-70);
[self.view addSubview:background];
UIView *background2 = [[UIView alloc] initWithFrame:CGRectMake(10, self.view.bounds.size.height-60, 300, 50)];
background2.backgroundColor = [UIColor whiteColor];
background2.layer.cornerRadius = 8;
background2.layer.masksToBounds = YES;
[background addSubview:background2];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 158, 50);
[button setTitle:@"myButton" forState:UIControlStateNormal];
[button addTarget:self action:@selector(myButton:) forControlEvents:UIControlEventTouchUpInside];
[background2 addSubview:button];
按钮不响应触摸?为什么呢?
答案 0 :(得分:2)
background.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-70);
UIView *background2 = [[UIView alloc] initWithFrame:CGRectMake(10, self.view.bounds.size.height-60, 300, 50)];
self.view.bounds.size.height-70
将此self.view.bounds.size.height-60
background2与背景框架
设置背景框self.view.bounds.size.height
现在它将完美无缺
答案 1 :(得分:0)
您的代码运行正常,我只是尝试过。
我只将background2
的框架更改为不在background
的框架之外。