我有UIViewController
名为MyViewController
。 MyViewController的视图有一个名为UIButton
的{{1}}作为子视图。然后MyViewController的视图添加另一个名为MyFirstButton
的子视图。 MySubView
直接放在MySubView
上方,因此看不到MyFirstButton
。 MyFirstButton
依次将MySubView
称为UIButton
作为子视图。
问题是 - 如果MySecondButton的框架与MyFirstButton的框架重叠,则MySecondButton
不响应。
我尝试通过将MySecondButton
设置为NO来设置MyViewController的视图并将YES设置为userInteractionEnabled
来尝试修复它,但它没有帮助。该按钮仍无响应。如何启用位于另一个按钮上的按钮?
答案 0 :(得分:0)
你无法对MySecondButton下的特定MyFirstButton使用该动作...我不认为这可以完成..你可以实际做的是隐藏MySecondButton点击它以显示MYFirstButton然后在MYFirstButton上点击它的动作执行并在第一个上面再次显示MYSecondButton :)同样用子视图隐藏2 ...
答案 1 :(得分:0)
试试这个,
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *firstButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[firstButton setTitle:@"first" forState:UIControlStateNormal];
firstButton.frame=CGRectMake(40, 70, 80, 80);
[firstButton addTarget:self action:@selector(firstButtonClicked) forControlEvents: UIControlEventTouchUpInside];
[self.view addSubview:firstButton];
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
[firstButton addSubview:view];
UIButton *secondButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[secondButton setTitle:@"second" forState:UIControlStateNormal];
secondButton.frame=CGRectMake(0, 0, 80, 80);
[secondButton addTarget:self action:@selector(secondButtonClicked) forControlEvents: UIControlEventTouchUpInside];
[view addSubview:secondButton];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)firstButtonClicked {
NSLog(@"first");
}
-(void)secondButtonClicked {
NSLog(@"second");
}