2

私はUIViewControllerと呼ばれていMyViewControllerます。MyViewControllerのビューには、サブビューとしてUIButton呼び出されます。MyFirstButton次に、MyViewControllerのビューは、と呼ばれる別のサブビューを追加しますMySubViewMySubView真上に配置されている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 に答える