Ios 长时间的压力和接触开始了

Ios 长时间的压力和接触开始了,ios,uiview,touchesbegan,touchesmoved,Ios,Uiview,Touchesbegan,Touchesmoved,当我在我的ViewController中检测到长按时,我会显示弹出菜单(将UIView添加为子视图)。长按结束时,我隐藏菜单(从superview中删除UIView)。因此,只有当用户触摸屏幕时,我的菜单才可见。问题是,当我在不触摸的情况下握住并移动手指时,我的菜单不会调用触摸开始或触摸移动,因此我无法从菜单中选择任何按钮。除了从ViewController传递事件,还有其他方法吗?我想在我的ui视图中执行此操作。请提供帮助。您最好的选择是将UIPangestureRecognitor添加到Vi

当我在我的
ViewController
中检测到长按时,我会显示弹出菜单(将
UIView
添加为子视图)。长按结束时,我隐藏菜单(从superview中删除
UIView
)。因此,只有当用户触摸屏幕时,我的菜单才可见。问题是,当我在不触摸的情况下握住并移动手指时,我的菜单不会调用
触摸开始
触摸移动
,因此我无法从菜单中选择任何按钮。除了从
ViewController
传递事件,还有其他方法吗?我想在我的
ui视图中执行此操作。请提供帮助。

您最好的选择是将
UIPangestureRecognitor
添加到ViewController的视图中。 就像这样:

UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[self.view addGestureRecognizer:panGestureRecognizer];
在实现
handlePanesture
中,您应该找到识别器相对于弹出视图的翻译

-(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
    }
}