這裏是我的工作代碼:子視圖用的UIButton無法點擊
UIButton *mainButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[mainButton setImage:[UIImage imageNamed:@"CircleShape.png"] forState:UIControlStateNormal];
mainButton.center = CGPointMake(self.view.frame.size.width/2.0f, self.view.frame.size.height/2.0f);
[self.view addSubview:mainButton];
UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 200, 100)];
[subView setBackgroundColor:[UIColor purpleColor]];
[mainButton addSubview:subView];
UIButton *secondButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[secondButton setImage:[UIImage imageNamed:@"CircleShape.png"] forState:UIControlStateNormal];
secondButton.center = CGPointMake(subView.frame.size.width/2.0f, subView.frame.size.height/2.0f);
[subView addSubview:secondButton];
爲什麼mainButton點擊,但secondButton是不是?
主按鈕的框架是100乘100,子視圖就是那麼多。所以第二個按鈕會熄滅。但是,正是你想用這個做什麼? – Durgaprasad 2013-05-14 12:01:51
何時在self.view中添加子視圖,然後這兩個按鈕將可點擊 – Rushabh 2013-05-14 12:06:05
謝謝,我會盡力實現這一點。我正在創建一個UIView子類,該UIBiew子類具有一個UIButton,當它按下時,會在mainButton的右側顯示一個選擇欄,其中有更多的按鈕可供選擇。這個DID工作。謝謝你們的幫助 – Parad0x13 2013-05-14 12:10:33