您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

iOS Dev (53):修復 UIImagePickerController 偷換 StatusBar 顏色的問題

編輯:iOS 開發綜合

使用系統相簿的 UIImagePickerController 時,有時會發現狀態欄(StatusBar)的顏色被默默改掉。可以在導覽控制器的代理方法中即時把它設回來:

- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated {
    // bug fixes: 修復 UIImagePickerController 使用中偷換 StatusBar 顏色的問題
    if ([navigationController isKindOfClass:[UIImagePickerController class]] &&
        ((UIImagePickerController *)navigationController).sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    }
}

透過判斷傳入的 navigationController 是否為 UIImagePickerController、且來源是相簿,就能精準攔下這個情況,把狀態欄的樣式強制設回預期值。

參考資料

  • https://my.oschina.net/megan/blog/167500
  • https://www.vinqon.com/codeblog/?detail/11109
  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved