Ios UIView上的UIView和UIView按钮不工作

Ios UIView上的UIView和UIView按钮不工作,ios,uiview,uibutton,Ios,Uiview,Uibutton,按钮对触摸不响应?为什么?你的代码很好用,我刚试过。 我只将background2的框架更改为不在background的框架之外 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 addSu

按钮对触摸不响应?为什么?

你的代码很好用,我刚试过。 我只将
background2
的框架更改为不在
background
的框架之外

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];
self.view.bounds.size.height-70
比较此
self.view.bounds.size.height-60
background2背景帧外

设置你的背景框
self.view.bounds.size.height
现在它可以完美地工作了


为什么要调用
initWithFrame
然后立即更改帧?当然!А编码12小时后,我不明白自己在做什么!))
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)];