gpt4 book ai didi

ios - UIView 和 UIButton 上的 UIView 不起作用

转载 作者:行者123 更新时间:2023-11-28 22:16:35 28 4
gpt4 key购买 nike

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 out of frame of background frame

enter image description here

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

enter image description here

关于ios - UIView 和 UIButton 上的 UIView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21493286/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com