2015-11-05 69 views
0

我在我的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];并没有帮助。可能是什么问题?

ViewController

Screen

+0

你想让按钮处理水龙头或UITapGestureRecognizer吗? – Yan

+0

我想要按钮来处理水龙头。但我想,按钮所在的视图必须至少处理tapGesturerecognizer,对吧? –

+0

也许你正在寻找这个(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)以获得澄清。 –

回答

0

如果你的观点并没有接收触摸

  1. 确保您UIViewuserInteractionEnabled设置为YES
  2. 的范围内确保该视图它的超级视图,以及超级视图在窗口的范围内。您可以使用打印视图帧NSLog(@"%@",NSStringFromCGRect(view.frame));
+0

如果您阅读了代码并查看了我发布的屏幕,您将看到我已将他们两个都检查过 –

+0

'bottomView',它的超级视图以及'[UIScreen mainScreen] .bounds'是什么框架? – Saif

+0

superview - {{0,0},{320,568}} bottomView - {{0,519},{320,49}} –

0

没有什么帮助。我不得不删除整个View Controller并重做整个事情。这显然解决了这个问题。