首页 > 解决方案 > 无法触发长按手势 [UiView]

问题描述

我对 iOS 和目标 c 非常陌生,我面临的问题是我无法正确地将长按手势识别器注册到我的视图中。我有点困惑,因为我已经以类似的方式添加了一个轻击手势识别器,并且效果很好。这就是我添加长按手势识别器的方式:

            UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action: @selector(onTap:)];
            UILongPressGestureRecognizer * longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action: @selector(longPress:)];

            [_pdfView addGestureRecognizer:longPressGesture];
            [_pdfView addGestureRecognizer:tapGesture];

这是我的长按功能:

-(void) longPress:(UILongPressGestureRecognizer *)sender {
    NSLog(@"longPress");
  
}

这是我的头文件:

@interface FLTPDFSandboxController : NSObject <FlutterPlatformView, CustomPdfViewDelegate>

- (instancetype)initWithFrame:(CGRect)frame;

-(void) onTap:(UITapGestureRecognizer *)sender;
-(void) longPress:(UILongPressGestureRecognizer *)sender;



- (UIView*)view;

@end

点击手势对我来说效果很好。这只是一个没有持续触发的长按。事实上,在一些非常罕见的情况下,它会以某种随机的方式触发。

谢谢你。

标签: iosobjective-c

解决方案


推荐阅读