我在我的UIView
中有很多子视图,其中很多子视图中有UIButtons
。其中一个子视图_bottomView
(坐标-(0,519,320,49))有错误。它无法识别放置在其中的按钮上的点击事件。子视图不被视为MainView的一部分
我试着放置一个UIButton
,覆盖整个_bottomView
,并且该按钮的点击事件(testButton
)也未被识别。
我尝试在代码中添加一个tapRecogniser,并且从每个点开始点击,除了_bottomView中的点被识别。下面
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[self.view addGestureRecognizer:gr];
_bottomView.userInteractionEnabled=true;
-(void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
CGPoint p = [gestureRecognizer locationInView:self.view];
NSLog(@"got a tap in the region i care about");
}
TapRecogniser代码我试图[self.view addSubview:_bottomView];
并没有帮助。可能是什么问题?
你想让按钮处理水龙头或UITapGestureRecognizer吗? – Yan
我想要按钮来处理水龙头。但我想,按钮所在的视图必须至少处理tapGesturerecognizer,对吧? –
也许你正在寻找这个(http://stackoverflow.com/questions/3344341/uibutton-inside-a-view-that-has-a-uitapgesturerecognizer)。 请阅读此文档(https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/event_delivery_responder_chain/event_delivery_responder_chain.html#//apple_ref/doc/uid/TP40009541-CH4-SW3)以获得澄清。 –