QLPreviewController delegate method doesn't get called in iOS 10, but does get called if ran earlier than iOS 10

痞子三分冷 提交于 2019-12-08 14:15:50

问题


Here is my code. This may sound like redundant question but my scenario is different as I am not adding QLPreviewController as a subview but present as a controller.

After downloading from dropbox, I present it like-

    self.pdfViewController = [[QLPreviewController alloc] init];
    self.pdfViewController.delegate = self;
    self.pdfViewController.dataSource = self;

    [self presentViewController:self.pdfViewController animated:YES completion:nil];

and I also have QLPreviewControllerDataSource, QLPreviewControllerDelegate listed as the protocol. Besides, it is working if being run in earlier than iOS 10.0.

Please help me.


回答1:


It looks like iOS 10 has changed the way that QLPreviewController is presented. On iOS 9 when I preview an image by presenting the QLPreviewController modally I see a nice zoom effect and the initial state of the preview is with a black background and the navigation and toolbar hidden. I can tap the image to make the bars visible (which changes the background to white). Tapping again toggles the state.

On iOS 10 the same code results in the white background view appearing and the zoom animation being incorrect (it seems to appear from off the bottom of the screen).

I found that implementing this practically undocumented new data source method for iOS 10 fixed the issue:

- (UIView* _Nullable)previewController:(QLPreviewController *)controller
          transitionViewForPreviewItem:(id <QLPreviewItem>)item
{
    return [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:MIDPhotoImageRowIndex_Image inSection:MIDPhotoSectionIndex_Image]];
}

The view I return is the same view that previewController:frameForPreviewItem:inSourceView: is using as the reference for the original content's frame (i.e. the image view in my table cell).

The documentation for this delegate method at the time of writing just says "No overview available".

Implementing that method did mean that the previewController:frameForPreviewItem:inSourceView: is now called on iOS 10. I just wish there was a way to default to the original black background without navigation bars.



来源:https://stackoverflow.com/questions/40590587/qlpreviewcontroller-delegate-method-doesnt-get-called-in-ios-10-but-does-get-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!