Iphone UIButton与另一个UIButton重叠时不响应
我有一个名为MyViewController的UIViewController。MyViewController的视图有一个名为MyFirstButton的UIButton作为子视图。然后MyViewController的视图添加另一个子视图,称为MySubView。MySubView直接放在MyFirstButton上,因此看不到MyFirstButton。MySubView有一个名为MySecondButton的UIButton作为子视图 问题是-如果MySecondButton的帧与MyFirstButton的帧重叠,则MySecondButton不会响应Iphone UIButton与另一个UIButton重叠时不响应,iphone,uikit,uibutton,Iphone,Uikit,Uibutton,我有一个名为MyViewController的UIViewController。MyViewController的视图有一个名为MyFirstButton的UIButton作为子视图。然后MyViewController的视图添加另一个子视图,称为MySubView。MySubView直接放在MyFirstButton上,因此看不到MyFirstButton。MySubView有一个名为MySecondButton的UIButton作为子视图 问题是-如果MySecondButton的帧与MyF
我试图通过为MyViewController的视图将userInteractionEnabled设置为NO,为MySubView设置为YES来修复它,但没有任何帮助。按钮仍然没有响应。如何启用位于另一个按钮上方的按钮?您不能对MySecondButton下的特定MyFirstButton使用该操作。。。我认为这是办不到的。。实际上,您可以在单击时隐藏MySecondButton以显示MYFirstButton,然后在MYFirstButton上单击执行其操作,并在第一个按钮的顶部再次显示MySecondButton:同样,使用子视图2进行隐藏…您不能将该操作用于正在运行的特定MYFirstButton我的第二个按钮。。。我认为这是办不到的。。实际上,您可以在单击时隐藏MySecondButton以显示MYFirstButton,然后在MYFirstButton上单击执行其操作并在第一个按钮的顶部再次显示MySecondButton:同样,使用子视图播放隐藏2…试试这个
- (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");
}
试试这个
- (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");
}
我需要使用secondButton的动作而不是第一个我需要使用secondButton的动作而不是第一个它们都没有响应所以两个方法都不会被调用太多的代码加帧都是在nib文件中设置的所以我担心它们都没有响应所以两个方法都不会被调用太多的代码加帧都是在nib文件中设置的nib文件,所以恐怕没有什么意义