6
votes

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!

2

2 Answers

3
votes

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

0
votes

Subclass QLPreviewController and then override

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

That's it!