2014-10-01 63 views
1

我的應用程序中的一個屏幕顯示了本地圖像的預覽,並且我在左上角有一個操作按鈕,用於顯示文檔交互選項:UIDocumentInteractionController沒有考慮到導航欄的色調

- (IBAction)actionButtonTapped:(id)sender { 
    self.interactionController = [UIDocumentInteractionController interactionControllerWithURL:self.attachmentLocalUrl]; 
    self.interactionController.delegate = self; 
    [self.interactionController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES]; 
} 

這種運作良好,因爲它顯示了一個動作片有一個選項列表,其中包括電子郵件,通過電子郵件發送附件。當我點擊電子郵件按鈕時,它會顯示電子郵件的預覽圖以及其中的圖像。但有一件事情不起作用。我已經定製了我的應用程序的外觀,以便導航欄在整個應用程序中具有相同的顏色。下面是我在我的應用程序委託的didFinishLaunchingWithOptions首先運行代碼:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 
[UINavigationBar appearance].barTintColor = [UIColor blueColor]; 
[UINavigationBar appearance].tintColor = [UIColor whiteColor]; 
[UINavigationBar appearance].titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]}; 

這非常適用於我自己的視圖控制器,而是由UIDocumentInteractionController顯示電子郵件預覽視圖控制器具有藍色而不是白色的欄按鈕的項目。由於其他參數正確應用,特別是導航欄的藍色背景,「取消」和「發送」操作按鈕幾乎不可見。

我已經嘗試在一個簡單的項目中重現這一點,但我不能。很顯然,我在我的應用程序中執行某些操作來干擾正常的定製。但我無法弄清楚什麼。任何想法我可能會調試?

+0

你可以試試這個代碼可以幫助全力爲您 的http://計算器。COM /問題/ 26177142 /創建-A-粘視圖到了-導航欄/ 26177826#26177826 – 2014-10-13 05:08:17

+0

你可以試試這個代碼 http://stackoverflow.com/questions/26177142/create-a-sticky - 查看導航欄/ 26177826#26177826 – 2014-10-13 05:09:27

+0

同樣的問題。已經注意到這隻發生在設備上而不是在模擬器上。 – 2014-12-09 18:25:48

回答

1

你能澄清一下你的意思嗎?導航欄上的顏色是在文檔選擇器還是mfmail聚合器上搞砸了?下面是一些代碼,或者雖然,我不得不使用...

如果它是在UIDocumentPicker,稱目前前設置此:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) 
{ 
    [[UIBarButtonItem appearance] setTintColor:[UIColor blackColor]]; 
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]]; 
} 

,然後將其改回您在didPickDocument有顏色和didCancel代表

,如果它是MFMailcomposer控制器上,然後使用此:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) 
{ 
    [controller.navigationBar setTintColor:[UIColor blackColor]]; 
} 

希望這有助於

+1

它是在UIDocumentInteractionController創建的MFMailComposeViewController中,當我在選項菜單中選擇「郵件」後。所以我不知道如何獲得對該視圖控制器的引用,以便強​​制導航欄的色調顏色像你一樣。 – Sebastien 2014-10-10 09:32:27

0

我在解決方法中解決了清除自定義之前呈現UIDocumentController,然後還原我的自定義主題viewWillAppear()呈現UIDocumentController的視圖控制器。

func launchDocumentController() { 
    UINavigationBar.appearance().titleTextAttributes = nil 
    UINavigationBar.appearance().barTintColor = nil 
    UINavigationBar.appearance().tintColor = nil 
    documentController.presentOptionsMenuFromRect(self.view.frame, inView: self.view, animated: true) 
} 

然後

public override func viewWillAppear(animated: Bool) { 
    super.viewWillAppear(animated) 
    // Restore the reset bar colors 
    Theme.current.customizeAppearance() 
} 

短的OS更新的,我覺得這是最好的回答「你會得到。抱歉。 (當我有機會時,我將提交一個雷達。)

如果您可以直接訪問MFMComposeViewController,如上所述設置色調顏色,是一種很好的解決方法。

0

這裏是完美的工作對我來說:

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController { 
    UINavigationBar.appearance().barTintColor = Colors.redColor() 
    UINavigationBar.appearance().tintColor = UIColor.white 
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white, NSFontAttributeName: UIFont.systemFont(ofSize: 14, weight: UIFontWeightBold)] 
    return self 
}