当我在ViewController
我显示弹出菜单中检测到长按时(将UIView
添加为子视图)。当长按结束时,我隐藏了我的菜单(从superview中删除UIView
)。所以我的菜单只有在用户触摸屏幕时才可见。问题是当我握住并移动手指而没有触摸时,我的菜单不会调用touchesBegan
或touchesMoved
,因此我无法从菜单中选择任何按钮。除了从ViewController
传递事件之外还有其他方法吗?我想在我的UIView
中这样做。求助。
答案 0 :(得分:1)
您最好的选择是将UIPanGestureRecognizer
添加到ViewControllers的视图中。
像那样:
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[self.view addGestureRecognizer:panGestureRecognizer];
在实施handlePanGesture
中,您应该相对于弹出视图找到识别器的翻译。
-(void)handlePanGesture:(id)sender {
UIPanGestureRecognizer *recognizer = sender;
if (recognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [recognizer translationInView:self.contentView];
//Here you can use translation to detect what button touched with gesture
}
}