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