8

In iOS 6 beta 4 and iOS 5.1.1 I have had left/right swipes allowing users to swipe between different QLPreviewControllers, hosted in a UIViewController.

In the released version of iOS 6 the swipes are now completely ignored.

Attempted to put a UIView as a subview of the preview controller in an attempt to get the view hosting the preview controller to intercept the swipes before the preview controller has a chance to swallow them, but these are never triggered.

Any one seen this or know of a work around.

Thanks,

Ben Whiting
  • 153
  • 1
  • 9

3 Answers3

2

I had the same problem but with UITapGestureRecognizer not working on QLPreviewController. In iOS 6 that thing is like a black hole for UIGestureRecognizer objects...nothing makes it out of there!

However I did find a workaround. I am subclassing QLPreviewController, so in my subclass I abused the (relatively) new viewWillLayoutSubviews method and added the following snippet:

UIView *overlay = [[UIView alloc] initWithFrame:self.view.frame];
overlay.backgroundColor = [UIColor whiteColor];
overlay.alpha = .002f;
for (UIView *v in self.view.subviews)
{
    [v addSubview:overlay];
}
[overlay release];

It may be overkill, but I basically went into the all of the quick look subviews and added a view to them that WOULD accept the gesture. I went with .002 alpha because making it lower would cause the gestures to be ignored again.

ghostatron
  • 2,620
  • 23
  • 27
  • Fantastic, thanks for this. While this does work I would note that you loose all of the standard QLPreviewController behaviour, zoom, scroll etc – Ben Whiting Oct 03 '12 at 16:16
  • Isn't this dangerous? Adding the same UIView instance as a subview to multiple views? An instance of a view can only appear once in a view hierarchy. – Echelon Oct 15 '12 at 11:11
  • It was a hack to begin with. Like Ben said, it blocks the built in QLPreviewController gestures. I actually gave up in the end and went with UIDocumentInteractionController. Can't put custom gestures on that one either, but it was a better match for what my team was looking for. Still not happy, but I had to move on. =-/ As for your question, I had no issues with reusing the view. But you can easily make the for loop create a new view for each overlay. – ghostatron Oct 15 '12 at 16:51
2

I have also found that using the same code, UIGestureRecognizers have stopped working under iOS 6. But it is not that totally broken. Apple Development Sample project "SimpleGestureRecognizers" still functions. After comparing the code, I found that explicitly "addGestureRecognizer" resolved the problem (besides all the other steps you used to do under IB). Assuming your one of your IBOutlets names leftSwiftRecognizer, you could do:

- (void)viewDidLoad
{
    [super viewDidLoad];
    ....
    // swipe recognizer
    [self.view addGestureRecognizer:self.leftSwiftRecognizer];

}
icezee
  • 63
  • 7
1

Your attempted solution was close, but probably backwards from what you should have done. Instead of adding another view as a subview of the preview controller, add the preview controller as a subview of the UIView.

Subview the preview controller inside a standard UIView. Then, reassign your gestures to the UIView's gestureRecognizers collection, removing them from the QLPreviewController's collection.

Not sure why this changed, but I had the same issue with my app, except for me it was the UITableView that wasn't scrolling anymore.

David Morton
  • 16,338
  • 3
  • 63
  • 73
  • 1
    Hi David, Thanks for suggestion, I tried the approach and it works in iOS 5, but in iOS 6 the QLPreviewController still blocks all gestures once the document is loaded. – Ben Whiting Sep 24 '12 at 10:06