Quicklook / QLPreviewController,iOS 8的一些问题,但一切都适用于iOS 7.1 [英] Quicklook/QLPreviewController, some problems with iOS 8 but everything works with iOS 7.1

查看:147
本文介绍了Quicklook / QLPreviewController,iOS 8的一些问题,但一切都适用于iOS 7.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用QuickLook查看PDF文件。

I'm working with QuickLook to view PDF Files.

它在iOS 7.1中正常工作但iOS 8 GM出现了一些问题。

It's working properly in iOS 7.1 but some problems happens with iOS 8 GM.

图片比文字好,我想告诉你问题:

Pictures are better than words, I wanna show you problems :

iOS 7.1 Xcode 6(工作正常)

使用QuickLook进行转换(没有失败)

页面滚动,导航栏隐藏得很好

-------------------------------- ------------------------------------------

现在,带有Xcode 6的iOS 8 GM

使用QuickLook进行转换.. 。

页面滚动,导航ationBar不隐藏,页面指示器隐藏在NavigationBar后面

与iPhone模拟器,iPad模拟器,iPhone设备和iPad设备相同的问题。

Same problem with iPhone simulator, iPad simulator, iPhone device and iPad device.

你可以在这里看到我的源代码:

You can see here my source code :

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController
{
    NSInteger numToPreview = 0;
    if (currentSection == CVSectionConvocations)
        numToPreview = self.convocation.convocations.count;
    else if (currentSection == CVSectionAttachments)
        numToPreview = self.convocation.attachements.count;
    return numToPreview;
}

- (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)idx
{
    PDF *pdf;
    if (currentSection == CVSectionConvocations)
        pdf = self.convocation.convocations[idx];
    else if (currentSection == CVSectionAttachments)
        pdf = self.convocation.attachements[idx];
    return [pdf path];
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    // determine section
    currentSection = (indexPath.section == 0 ? CVSectionConvocations : CVSectionAttachments);

    PDF *pdf;
    if (currentSection == CVSectionConvocations)
        pdf = self.convocation.convocations[indexPath.row];
    else if (currentSection == CVSectionAttachments)
        pdf = self.convocation.attachements[indexPath.row];

    if ([pdf isStored]) {
        QLPreviewController *previewController = [[QLPreviewController alloc] init];
        previewController.dataSource = self;
        previewController.delegate = self;

        previewController.currentPreviewItemIndex = indexPath.row;
        [[self navigationController] pushViewController:previewController animated:YES];
    } else {
        [self displayMessage:@"Document not found" title:@"Oups !"];
    }
}

感谢您的帮助;)

推荐答案

我遇到了与转换相同的问题。我的解决方案是将previewController存储在一个属性中,并在我的呈现视图控制器中的viewDidLoad中初始化一次。

I got the same problem with the transition. My solution was to store the previewController in a property and initialize it once in viewDidLoad in my presenting view controller.

每次推送时我还必须设置currentPreviewItemIndex等于0预览控制器,虽然我当时只显示一个文件。如果我没有设置值,默认情况下不会打开zip文件,预览控制器会显示显示内容按钮,而是会打开一个遇到相同转换问题的新预览控制器。

I also had to set the currentPreviewItemIndex equals 0 every time I push the previewcontroller, although I'm only showing one file at the time. If I'm not setting the value zip files are not opened by default and the preview controller shows a 'Show contents' button instead which will open a new preview controller suffering the same transition issue.

我还在尝试修复隐藏的导航栏问题。在 apple示例项目中,一切正常。似乎模态呈现导航控制器会导致我的项目出现问题。

I'm still trying to fix the not hiding navigation bar issue. In the apple sample project everything works fine. It seems that modally presenting the navigation controller causes the problem in my project.

编辑:

这对我来说肯定是个错误。仅当导航控制器呈现为模态时,才会显示导航栏的问题。在我看来,预览控制器创建了一个新的导航控制器和一个新的导航栏。这个隐藏在主机导航控制器的导航栏下。此截图显示了问题:

It definitely seems to be a bug to me. The problem with the navigation bar only appears if the navigation controller is presented modal. It seems to me that the preview controller creates a new navigation controller and also a new navigation bar. This one is hidden under the navigation bar of the hosting navigation controller. This screenshot shows the problem quite well:

蓝色突出显示的栏是self.navigationBar,蓝色框架栏属于预览控制器。只有当导航控制器呈现为模态时才会发生这种情况。

The blue highlighted bar is self.navigationBar and the blue framed one belongs to the preview controller. Again this happens only if the navigation controller is presented modal.

我的解决方法是将我的视图控制器设置为导航控制器委托并在预览后立即隐藏导航栏控制器被推。我只在iOS 8.0和8.1上测试了我的代码。

My workaround is to set the my view controller as the navigation controllers delegate and hide the navigation bar as soon the preview controller is pushed. I only tested my code on iOS 8.0 and 8.1.

- (void)viewDidLoad {
    [super viewDidLoad];

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

    self.navigationController.delegate = self;
}

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    // Workaround:
    // If the previewController is pushed to a navigation controller which is presented modal, it appears that the preview controller adds a second navigation bar (and navigation controller).
    // This results in a UI glitch that one nav bar is always visible. To prevent this we hide our navigation bar so that only the one owned by the preview controller is visible.
    // Note that this only happends if the navigation controller is presented modal, thus it seems to be an iOS bug.
    if (viewController == self.previewController) {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
    }    
}

这篇关于Quicklook / QLPreviewController,iOS 8的一些问题,但一切都适用于iOS 7.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆