【发布时间】:2012-11-28 10:47:59
【问题描述】:
我有这个运行良好的方案(--> = "has subview"):
ViewController.view --> imageView --> containerView --> UIButton
正如预期的那样,按钮会触发指定的选择器。
但是,如果我执行以下操作(出于多种原因,最好这样做)按钮停止接收触摸。
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 看起来像这样:
【问题讨论】:
-
大概您已经尝试在整个层次结构中设置“@property(nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled”?
-
@Ōkami 是的。所有
userInteractionEnabled都已设置。否则,如果添加到图像视图中,按钮将不起作用,对吧? -
@Mundi:你是在向 imageView 添加按钮吗?
-
没有。我觉得上面的解释很清楚了。
标签: iphone ios uibutton touch subview