0

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

1 回答 1

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

qlPreviewControllerQLPreviewController是那里的看法的对象UILongPressGestureRecognizer

qlPreviewControllerview不是viewcontroller确定!

更新 :

例如;

  QLPreviewController *vc;  

  UIView *qlPreviewController = vc.view;

更新 2:

您可以使用它delegate method来禁用手势识别器!

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

    return NO;


 }
于 2016-09-08T10:05:58.193 回答