您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 程式設計技術

iOS 7 與 iOS 8 半透明模態彈出視窗寫法

編輯:iOS 程式設計技術

若要以半透明模態方式顯示自訂彈出視窗,可設定 modalPresentationStyle。在 iOS 8 以上,通常使用 UIModalPresentationOverCurrentContext,讓背景保持可見。

MKDialogController *controller = [[MKDialogController alloc] init];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
    controller.providesPresentationContextTransitionStyle = YES;
    controller.definesPresentationContext = YES;
    controller.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    [self presentViewController:controller animated:YES completion:nil];
}

若需要相容 iOS 7,可改用 rootViewController 的 modalPresentationStyle,在 present 前後切換 UIModalPresentationCurrentContext 與 UIModalPresentationFullScreen。實際效果會受系統版本與控制器階層影響,建議在真機與模擬器上測試。

  1. 上一篇文章:
  2. 下一篇文章: No
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved