【问题标题】:Document interaction controller with iOS 7 status bar?带有 iOS 7 状态栏的文档交互控制器?
【发布时间】:2013-10-27 05:18:51
【问题描述】:

UIDocumentInteractionController 似乎无法与新的 iOS 7 状态栏正确交互,尤其是在横向时。我现在用于显示查看器的代码:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"pdf"];
    NSURL *url = [NSURL fileURLWithPath:filePath];

    UIDocumentInteractionController *pdfViewer = [UIDocumentInteractionController interactionControllerWithURL:url];
    [pdfViewer setDelegate:self];
    [pdfViewer presentPreviewAnimated:YES];
}

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return self;
}

- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
    return self.view;
}

当交互控制器首次出现时,状态栏与标题重叠。

在另一侧旋转到横向暂时修复了该行为。

正如预期的那样,点击文档本身可以关闭框架。但是,一旦再次点击文档以激活框架,就会再次发生重叠,就像第一张图像一样。

我尝试设置documentInteractionControllerRectForPreview 无济于事。

- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
{
    return CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height);
}

我不希望在交互控制器出现时隐藏状态栏,我认为可以正确执行此操作,因为 Mail 应用程序行为正确,并且看起来它使用的是同一个类。

为任何想使用代码的人附加一个最小的示例项目: https://hostr.co/PiluL1VSToVt

【问题讨论】:

  • 这是 iOS 7 中的错误吗?有新的解决方案吗?我使用相同的方法来解决问题,但它导致了我的应用程序中的另一个错误。

标签: ios cocoa-touch ios7 statusbar uidocumentinteraction


【解决方案1】:

我通过将UIDocumentInteractionController 包装在UINavigationController 中并将应用程序窗口的根视图控制器切换到导航控制器进行演示来解决了这个问题。在我的使用中,其他视图控制器没有使用UINavigationController,因此在解雇时我们将旧的根控制器换回:

#import "MainViewController.h"

@interface MainViewController ()

@property (nonatomic, strong) UINavigationController *navController;
@property (nonatomic, strong) MainViewController *main;

@end

@implementation MainViewController

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    self.main = self;
    self.navController = [[UINavigationController alloc] initWithRootViewController:[UIViewController new]];
    [[UIApplication sharedApplication].keyWindow setRootViewController:self.navController];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"pdf"];
    NSURL *url = [NSURL fileURLWithPath:filePath];

    UIDocumentInteractionController *pdfViewer = [UIDocumentInteractionController interactionControllerWithURL:url];
    [pdfViewer setDelegate:self];
    [pdfViewer presentPreviewAnimated:YES];
}

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return self.navController;
}

- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
    [[UIApplication sharedApplication].keyWindow setRootViewController:self.main];
    self.main = nil;
}

- (void)dismiss
{
    [self.navController popViewControllerAnimated:YES];
}

@end

虚拟视图控制器允许弹出交互控制器(后退按钮)。

【讨论】:

    【解决方案2】:

    找到了新的解决方案。

    在 info.plist 文件中为 iOS 7 添加: UIViewControllerBasedStatusBarAppearance(基于视图控制器的状态栏外观)= NO

    【讨论】:

      【解决方案3】:

      这些解决方案对我不起作用。我发现的唯一解决方案是在委托请求呈现视图控制器后强制状态栏在下一个运行循环中可见(也需要将 UIViewControllerBasedStatusBarAppearance 设置为 NO):

      - (UIViewController *) documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *) controller {
          // hack to keep status bar visible
          [[NSOperationQueue mainQueue] addOperationWithBlock:
           ^{
               [[UIApplication sharedApplication] setStatusBarHidden:NO];
           }];
          return self.viewController;
      }
      

      【讨论】:

        【解决方案4】:

        试试下面的代码它对我有用:

        - (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller
        {
            [[UIApplication sharedApplication] setStatusBarHidden:YES];
        }
        
        - (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
        {
            [[UIApplication sharedApplication] setStatusBarHidden:YES];
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-08-03
          • 2013-10-13
          • 1970-01-01
          • 2013-09-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多