我有這個方案,其工作正常(-->
=「具有子視圖」):加入self.view時的UIButton沒有得到觸摸
ViewController.view --> imageView --> containerView --> UIButton
正如預期的那樣,按鈕觸發關閉指定選擇器。
但是,如果我做了以下(由於幾個原因是可取的)按鈕停止接收觸摸。
ViewController.view --> imageView
ViewController.view --> containerView --> UIButton
[self.view bringSubviewToFront:_containerView];
任何導致?
- UPDATE
響應請求,這裏是一些按鈕創建代碼:
// in viewDidLoad
_controlsView = [[[NSBundle mainBundle] loadNibNamed:@"Controls"
owner:self options:nil] objectAtIndex:0];
_controlsView.frame = CGRectMake(0, 50,
_controlsView.bounds.size.width, _controlsView.bounds.size.height);
[self.view addSubview:_controlsView];
// ...
[_controlsView.superview bringSubviewToFront:_controlsView];
// in viewDidAppear
if (!_demoButton) {
_demoButton = (UIButton*)[_controlsView viewWithTag:kDemoButtonTag];
[_demoButton addTarget:self action:@selector(buttonPressed:)
forControlEvents:UIControlEventTouchUpInside];
// configuration, color, font, layer, etc. all works well
}
最後,Controls.xib
看起來是這樣的:
假設你已經嘗試在整個層次結構中設置「@property(nonatomic,getter = isUserInteractionEnabled)BOOL userInteractionEnabled」 –
@Ōkami是的。所有'userInteractionEnabled'都被設置。否則,它的按鈕將無法正常工作,如果添加到圖像視圖,對不對? – Mundi
@Mundi:你是否將按鈕添加到imageView? –