我有这个工作正常的方案(-->
=“有子视图”):
ViewController.view --> imageView --> containerView --> UIButton
正如预期的那样,按钮会触发指定的选择器。
但是,如果我执行以下操作(出于多种原因,最好这样做),按钮将停止接收 touches。
ViewController.view --> imageView
ViewController.view --> containerView --> UIButton
[self.view bringSubviewToFront:_containerView];
有什么线索吗?
- 更新
响应请求,这里是一些按钮创建代码:
// 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
看起来像这样: