I have a UIView
as the main view and add a QLPreviewController
as the subview over that while previewing the document. I want to restrict the long press gesture so that no one can copy contents from the document. I have tried the following code:
Code Snippet :
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];
But no success. Can anyone tell me where am I going wrong and what could be done to disable the long press gesture ?
I have tried this as well :
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]];
}
}
You can do something like,
NSArray *arr = qlPreviewController.gestureRecognizers;
for (int i = 0; i < arr.count; i++) {
if ([[arr objectAtIndex:i] isKindOfClass:[UILongPressGestureRecognizer class]]) {
[qlPreviewController removeGestureRecognizer:[arr objectAtIndex:i]];
}
}
qlPreviewController
is the object of QLPreviewController
's view on wich UILongPressGestureRecognizer
is there!
qlPreviewController
is view
not viewcontroller
make sure that!
Update :
for example;
QLPreviewController *vc;
UIView *qlPreviewController = vc.view;
Update 2:
you can use this delegate method
to disable gesture recognizer!
- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return NO;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.