繁体   English   中英

关于UIView和UIButton的UIView不起作用

[英]UIView on UIView and UIButton not work

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];

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

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现在它将完美地工作

在此输入图像描述

你的代码工作正常,我只是尝试过。 我只改变了帧background2为不是的框架的外侧background

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM