- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 UIImageView 中添加了 4 个手势识别器,单击、双击和 pin 手势工作正常。但是,长按手势不起作用。这是为什么?
_imageView.userInteractionEnabled = YES ;
//single tap
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc ]initWithTarget:self action:@selector(singleTapAction:) ] ;
singleTap.numberOfTapsRequired = 1 ;
singleTap.numberOfTouchesRequired = 1 ;
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapAction:)] ;
doubleTap.numberOfTouchesRequired = 1 ;
doubleTap.numberOfTapsRequired = 2 ;
[singleTap requireGestureRecognizerToFail:doubleTap] ;
//pin gesture
UIPinchGestureRecognizer *pin = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)] ;
//long press gesture
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:) ] ;
[longPress requireGestureRecognizerToFail:singleTap ] ;
longPress.minimumPressDuration = 1 ;
longPress.numberOfTouchesRequired = 1 ;
longPress.numberOfTapsRequired = 1 ;
[_imageView addGestureRecognizer:longPress] ;
[_imageView addGestureRecognizer:pin] ;
[_imageView addGestureRecognizer:singleTap] ;
[_imageView addGestureRecognizer:doubleTap] ;
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
shouldRecognizeSimultaneouslyWithGestureRecognizer
方法并设置长按 gesutre 委托(delegate),但这仍然不起作用。
最佳答案
你的错误可能在这里
[longPress requireGestureRecognizerToFail:longPress ] ;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.imageView.userInteractionEnabled = YES;
self.imageView.multipleTouchEnabled = YES;
UIGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1 ;
longPress.numberOfTouchesRequired = 1 ;
[longPress requireGestureRecognizerToFail:pinchGesture];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
doubleTap.numberOfTouchesRequired = 1;
doubleTap.numberOfTapsRequired = 2;
[doubleTap requireGestureRecognizerToFail:longPress];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
singleTap.numberOfTouchesRequired = 1;
singleTap.numberOfTapsRequired = 1;
[singleTap requireGestureRecognizerToFail:doubleTap];
[self.imageView addGestureRecognizer:pinchGesture];
[self.imageView addGestureRecognizer:longPress];
[self.imageView addGestureRecognizer:doubleTap];
[self.imageView addGestureRecognizer:singleTap];
}
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gesture{
NSLog(@"Pinch");
}
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture{
NSLog(@"LongPress");
}
- (void)handleDoubleTap:(UITapGestureRecognizer *)gesture{
NSLog(@"Double Tap");
}
- (void)handleSingleTap:(UITapGestureRecognizer *)gesture{
NSLog(@"Single Tap");
}
关于ios - UILongPressGestureRecognizer 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20762513/
在我的应用程序中,我希望 UILongPressGestureRecognizer 每秒发送连续的消息,直到释放按钮。不幸的是,没有像“连续”这样的状态,所以我需要使用“开始”和“结束”来控制我的消息
我正在尝试创建一个应用程序,当触发 UILongPressGestureRecognizer 手势时,可以拖放 UIButtons。 我有: UIGestureRecognizer *longPres
我正在开发一个应用程序,其中我在 View 上应用 UILongPressGesture 识别器,并实现了为事件(发生时长按手势)实现的代码。 处理手势的代码写在一个方法中,当我尝试长按不需要的 Vi
我尝试在我的应用程序中使用 UILongPressGestureRecognizer,问题是该函数仅在我稍微移动手指时调用。 这是我正在使用的代码: UILongPressGestureRec
我在 UIImageView 中添加了 4 个手势识别器,单击、双击和 pin 手势工作正常。但是,长按手势不起作用。这是为什么? _imageView.userInteraction
我想让一个 UI 按钮只有在按住超过设定的秒数时才会响应。所以我这样使用了 UILongPressGestureRecognizer: import UIKit class ViewControlle
我有一个问题,当长按时,快速移动手指,并且在回调函数中我无法检测到手指已经在某个区域,如果你移动手指足够快的话。这是我的猜测:回调函数有一个最大频率,有人知道它的确切数量吗? 最佳答案 也许更好用 t
当用户将手指按在屏幕上时,我想执行一个连续的 Action 。这目前工作正常。但是当用户将第二根手指按在屏幕上时,我希望 UILongPressGestureRecognizer 取消/结束第一次按下
我已将 UILongPressGestureRecognizer 添加到 UITextField 中。当我按下 UITextField 时,它会向我显示警报,但这是三个警报向我显示。这是我的代码: -
我在 viewDidLoad 中有这段代码: UILongPressGestureRecognizer *change = [[UILongPressGestureRecognizer alloc]
我正在尝试创建一个应用程序,其中可以在触发 UILongPressGestureRecognizer 手势时拖放 UIButton。实际上,我的应用程序在任何 iPad 上都运行良好。它仅在 iPho
我已将 UILongPressGestureRecognizer 连接到 View 上的 Button。我在 Interface Builder 的 Referencing Outlet Collec
这适用于 iOS 11 上的设备,但随着我的设备更新到 iOS 12,它不再适用: //the viewcontroller is initiated with UIGestureRecognizer
我正在尝试制作一个功能,当用户按住手指时,图像会在发生过渡时变大,直到达到一定大小。我知道如何使图像变大,但不知道如何使其仅在用户按住时才变大。 有谁知道如何做到这一点?是否需要 LongPressR
我想让屏幕的右侧使节点跳转,左边的前半部分向左移动,后半部分向右移动。 一些不合适的东西: 当我快速左、右、左、右多次点击时(它会停止并且不会移动节点) 当我点击屏幕右侧并点击左侧或右侧部分时,并非每
我目前有一个使用生成按钮列表的 SimpleAlert 制作的操作表。这些按钮可识别轻击和长按。在长按时,我试图通过选择器将按钮作为发件人传递,以便访问另一个函数中的按钮标签,但是它一直给我这个错误:
我以这种方式在 UIImageView 上使用 UILongPressGestureRecogniser: UILongPressGestureRecognizer *longPress = [[UI
我正在尝试了解手势识别器的工作原理,并尝试让手势识别器告诉我长触摸何时开始以及何时结束,即使触摸没有移动也是如此。 在 viewDidLoad 中,我添加了一个名为 game 的 subview 。在
我想检测 UIWebView 的 UILongPressGestureRecognizer 点击并按住 .. 这样当我长按将近 3 秒时,下面的 if 条件应该是 True 那么只有 if (navi
我用 UILongPressGestureRecognizer 为 UIImageView 设置了动画,如下所示: override func viewDidAppear(animated: Bool
我是一名优秀的程序员,十分优秀!