簡體   English   中英

如何禁用QLPreviewController的長按手勢

[英]How to disable the long press gesture of a QLPreviewController

我有一個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]];
     }
}

你可以做類似的事情,

NSArray *arr = qlPreviewController.gestureRecognizers;

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

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

        [qlPreviewController removeGestureRecognizer:[arr objectAtIndex:i]];
    }
}

qlPreviewControllerQLPreviewControllerUILongPressGestureRecognizer上的視圖的對象!

qlPreviewControllerview而不是viewcontroller確保!

更新:

例如;

  QLPreviewController *vc;  

  UIView *qlPreviewController = vc.view;

更新2:

您可以使用此delegate method禁用手勢識別器!

  - (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{

    return NO;


 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM