iOS 6 UIGestures (Swipe) stops working with QLPreviewController
Asked Answered
T

3

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,

Thermostatics answered 21/9, 2012 at 12:43 Comment(1)
I am having a similar issue with a project I am involved with.Mccullough
S
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.

Savour answered 28/9, 2012 at 1:12 Comment(3)
Fantastic, thanks for this. While this does work I would note that you loose all of the standard QLPreviewController behaviour, zoom, scroll etcThermostatics
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.Concordia
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.Savour
B
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];

}
Balladry answered 1/11, 2012 at 7:52 Comment(0)
D
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.

Deanndeanna answered 21/9, 2012 at 17:39 Comment(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.Thermostatics

© 2022 - 2024 — McMap. All rights reserved.