2013-10-18 37 views
6

UIDocumentInteractionController似乎無法正確與新的iOS 7狀態欄進行交互,特別是在橫向模式下。我現在用於顯示查看器的代碼:具有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; 
} 

當交互控制器第一次出現時,狀態欄與標題重疊。

enter image description here

旋轉爲橫向另一側暫時修復該問題。

enter image description here

正如預期的那樣輕敲文件本身允許駁回幀。但是,一旦再次點擊文檔以激活框架,重疊就會像第一張圖像一樣再次出現。

我試過設置documentInteractionControllerRectForPreview無濟於事。

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

我不想隱藏狀態欄時,交互控制器來了,我認爲這是可能的,因爲在郵件應用程序正確行爲正確地做到這一點,它看起來像它使用的是同一類。

連接誰想要的代碼打小例子項目: https://hostr.co/PiluL1VSToVt

+0

它是iOS 7中的錯誤嗎?有新的解決方案嗎?我用相同的方式來解決問題,但它在我的應用程序中造成了另一個錯誤。 – GxocT

回答

0

我被包裹在一個UINavigationControllerUIDocumentInteractionController和應用程序窗口的根視圖控制器切換到導航控制器呈現解決了這個。在我的使用的另一視圖控制器沒有使用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 

虛設視圖控制器允許交互控制器被(後退鍵)彈出。

0

找到新的解決方案。

在Info.plist文件中添加此爲iOS 7: UIViewControllerBasedStatusBarAppearance(查看基於控制器的狀態欄外觀)= NO

0

這些解決方案並沒有爲我工作。我發現的唯一的解決辦法是強制狀態欄可見的未來runloop委託後請求呈現視圖控制器(需要UIViewControllerBasedStatusBarAppearance設置爲NO也):

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

試試下面的代碼工作對我來說:

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

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