2

我有一个UIViewControllerMyViewController. MyViewController 的视图有一个UIButton称为MyFirstButton子视图。然后 MyViewController 的视图添加了另一个名为MySubView. MySubView直接放在上面MyFirstButton,所以MyFirstButton看不到。MySubView反过来又UIButton被称为MySecondButton子视图。

问题是 - 如果 MySecondButton 的框架与 MyFirstButton 的框架重叠,MySecondButton则不响应。

我试图通过将userInteractionEnabledMyViewController 的视图设置为 NO 并将 设置为 YES来修复它MySubView,但它没有帮助。按钮仍然没有响应。如何启用位于另一个上方的按钮?

4

2 回答 2

0

您不能对 MySecondButton 下的特定 MyFirstButton 使用该操作...我不认为可以这样做..您实际上可以做的是在单击时隐藏 MySecondButton 以显示 MYFirstButton,然后在单击 MYFirstButton 时执行其操作并在第一个顶部再次显示 MYSecondButton :) 同样隐藏子视图 2 ...

于 2012-09-05T11:34:26.247 回答
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");
}
于 2012-09-05T11:41:32.520 回答