Custom QLPreviewController or UIDocumentInteractionController that can intercept touch events
Asked Answered
H

2

6

Ok, so what I am trying to do is create a Document Viewer that is similar this picture: enter image description here

Basically what should happen is, when the screen is tapped anywhere, the top and bottom bar will appear. Tap again and they disappear.

I have subclassed QLPreviewController and have managed to leverage the (top) navigation bar that already comes with QLPreviewController. This works fine. Now I need to get the bottom bar to display whenever the top bar is displayed. I can add a UIToolbar to the bottom of the page, but I need to intercept the touch events so I can hide/unhide the bottom bar. I cannot seem to figure out how to get it to work. I tried adding a UITapGestureRecognizer to the view of the QLPreviewController subclass itself to no luck. I also tried creating an overlay UIView that has a UITapGestureRecognizer but that prevented the user form interacting with the document underneath.

Anyone have any ideas at all on how to do this? Thanks in advance!

Hammond answered 15/5, 2012 at 17:19 Comment(0)
H
3

Ok, I figured out what the issue was with the UITapGestureRecognizer. You need to set the delegate to self, and then override the

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

function and return yes. So in my QLPreviewController subclass, I implemented the UIGestureRecognizerDelegate, and in the viewWillAppear:

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(documentTapped:)];
tapGesture.cancelsTouchesInView = NO;
tapGesture.delegate = self;
[self.view addGestureRecognizer:[tapGesture autorelease]];

Then simply:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

This way, the QLPreviewController will still receive all the other non-tap touch events so that the user can still interact with the document

Hammond answered 16/5, 2012 at 1:39 Comment(0)
D
0

Subclass QLPreviewController and then override

-(void)contentWasTappedInPreviewContentController:(id)item {}

That's it!

Dispensatory answered 6/2, 2014 at 16:32 Comment(1)
Unfortunately this doesn't seems to be a valuable solution since apple consider it a private API. see #6091527Alburga

© 2022 - 2024 — McMap. All rights reserved.