Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom QLPreviewController or UIDocumentInteractionController that can intercept touch events

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!

like image 587
baselq Avatar asked May 15 '12 17:05

baselq


1 Answers

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

like image 194
baselq Avatar answered Sep 28 '22 21:09

baselq