【iOS8】presentViewControllerで透過viewを表示する
iOS8以前(いつからかは知らない)はpresentViewControllerで透過viewを表示するには以下のようなコードを書いていたと思う。
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController; rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
以下参考サイト。
presentViewControllerで元の画面も見えるようにするのがうまくいかない - uokumuraの日記
UIViewのbackgoundcolorをclearcolorにしたのに背景が透明にならない : iPhoneアプリ開発・Objective-C勉強まとめ
ただし現時点(2014/09/11)でXCode6 GM Seedでシミュレータ上で動かしる限りだと正しく動いていない模様(真っ黒になってしまう)。
stackoverflowにも同じようなことありました。
ios8 - How to present a semi-transparent (half-cut) viewcontroller in iOS 8 - Stack Overflow
ただしここに書いてあるサンプルがよくわからずどうしようかと思っていたところ、もくもくiOS勉強会@Rettyで"WWDCのビデオにそれぽいものあったよ"とアドバイスいただいたので調べてみた。
WWDC 2014 Session Videos - Apple Developer
"A Look Inside Presentation Controllers"というセッションですね。
で、UIPresentationControllerあたりの新しいAPI使わなくちゃいけないかななんて身構えていたけど、以下のような感じであっさりできた。
HogeViewController *vc = [[HogeViewController alloc] init]; vc.modalPresentationStyle = UIModalPresentationOverFullScreen; [self presentViewController:vc animated:NO completion:nil];
とはいえUIPresentationControllerまわりもiOS8では重要になってきそうなのでキャッチアップできるようにはしよう。