如何禁用QLPreviewController的长按手势

时间:2016-09-08 09:54:44

标签: ios objective-c qlpreviewcontroller uilongpressgesturerecogni

我有一个UIView作为主视图,并在预览文档时添加QLPreviewController作为子视图。我想限制长按手势,以便没有人可以从文档中复制内容。我尝试了以下代码:

代码段:

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:nil]; 

longPress.allowableMovement=100; 

longPress.minimumPressDuration=0.3; 
longPress.delegate=self; 
longPress.delaysTouchesBegan=YES;
longPress.delaysTouchesEnded=YES;

longPress.cancelsTouchesInView=YES; 
[previewController.view addGestureRecognizer:longPress]; 
[self.view addSubview:previewController.view];

但没有成功。谁能告诉我哪里出错了?如何禁用长按手势呢?

我也试过这个:

NSArray *arr = previewController.view.gestureRecognizers;

for (int i = 0; i < arr.count; i++) {

     if ([[arr objectAtIndex:i] isKindOfClass:[UILongPressGestureRecognizer class]]) {

         [previewController.view removeGestureRecognizer:[arr objectAtIndex:i]];
     }
}

1 个答案:

答案 0 :(得分:0)

你可以做点什么,

NSArray *arr = qlPreviewController.gestureRecognizers;

for (int i = 0; i < arr.count; i++) {

    if ([[arr objectAtIndex:i] isKindOfClass:[UILongPressGestureRecognizer class]]) {

        [qlPreviewController removeGestureRecognizer:[arr objectAtIndex:i]];
    }
}
{p> qlPreviewControllerQLPreviewController的{​​{1}}视图的对象!

UILongPressGestureRecognizer qlPreviewController而非view确保!

更新:

例如

;

viewcontroller

更新2:

您可以使用此 QLPreviewController *vc; UIView *qlPreviewController = vc.view; 来禁用手势识别器!

delegate method