【发布时间】:2015-11-05 05:30:53
【问题描述】:
我的UIView 中有很多子视图,其中许多子视图中有UIButtons。其中一个子视图-_bottomView(坐标-(0,519,320,49))有错误。它无法识别放置在其中的按钮上的单击事件。
我尝试放置一个覆盖整个_bottomView 的UIButton,并且该按钮(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");
}
我试过[self.view addSubview:_bottomView];,但也没有用。可能是什么问题?
【问题讨论】:
-
你想让按钮处理点击还是UITapGestureRecognizer?
-
我想要按钮来处理水龙头。但我想,按钮所在的 View 必须至少处理 tapGesturerecognizer,对吧?
-
也许你正在寻找这个(stackoverflow.com/questions/3344341/…)。请阅读此文档 (developer.apple.com/library/ios/documentation/EventHandling/…) 进行说明。
-
该按钮应该处理它自己的点击,除非您需要按钮和视图处理单独的点击,正如@RahulWakade 指出的那样。
-
@RahulWakade 不,那篇文章没有帮助。在他的情况下,发问者有 UITapGestureRecognizer 工作。我的应用中不需要 tapRecognizer。我只是将其放入以检查是否在该特定视图中检测到 Tap。
标签: ios objective-c uiview uitapgesturerecognizer