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!

rishi
  • 11,779
  • 4
  • 40
  • 59
baselq
  • 301
  • 6
  • 17

2 Answers2

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

baselq
  • 301
  • 6
  • 17
0

Subclass QLPreviewController and then override

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

That's it!

sth
  • 222,467
  • 53
  • 283
  • 367
SRP-Achiever
  • 435
  • 4
  • 9
  • Unfortunately this doesn't seems to be a valuable solution since apple consider it a private API. see http://stackoverflow.com/questions/6091027/qlpreviewcontrollers-view#comment34156919_22231721 – Lifely Aug 18 '14 at 12:59