LoginSignup
22
21

More than 5 years have passed since last update.

iOSアプリのpresentViewControllerの背景透過のOSバージョン別の書き方

Last updated at Posted at 2015-03-01

カスタマイズされたアラートを出したい

UIAlertViewのカスタマイズとして、モーダルビューをよびだして背景透過をする手法。

OSのバージョンが変わるごとにmodalの設定方法が変わって、完全に闇の原因になっている。。。

まずiOS6の書き方

self.tabBarController.modalPresentationStyle = UIModalPresentationCurrentContext;

iOS7のとき

self.tabBarController.modalPresentationStyle = UIModalPresentationCurrentContext;

iOS8のとき

self.tabBarController.modalPresentationStyle = UIModalPresentationOverCurrentContext;

設定する時の注意

また、このコードを反映させる時にまた注意が一つ。
こちらで紹介した通りに、モーダルビューの設定にはもう一つ注意が必要だそうです。

どのOSのタイプでもmodalPresentationStyleを設定する対象を以下のように変えていかなければならないらしく。

self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;

表示するVIewControllerがnavigatoincontrollerかtabbercontrollerを含んでる時はnavigationcontrollerかtabbercontrollerのmodalPresentationStyleに設定。

こういうちょっとしたところでつまずいて闇に頭を抱えるの怖すぎますね。

参考

22
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
21