LoginSignup
26
24

More than 5 years have passed since last update.

iOSでポップアップビューを実装する(with Storyboard)

Last updated at Posted at 2014-08-24

昨日の記事の「iOSでポップアップビューを実装する」ではうまく実現できなかったStoryboardを使ったポップアップビューの実装ですが、mono0926さんのアドバイスを受けて、再度Storyboardを使ってポップアップビューを実現してみました。

modalTransitionStyleを設定する。

今回はiOS7での対応を試してみます。(iOS8版は後日)

ViewController.m

- (void)viewDidLoad
{
  [super viewDidLoad];

  self.modalPresentationStyle = UIModalPresentationCurrentContext;

}

呼び出し側のViewControllerのmodalPresentationStyleを設定することでPopupViewControllerがモーダルで表示されたときも、下にあるビューは存在しているので透過して上に乗っているように見えます。

アニメーション設定

modalPresentationStyleを設定することで、入りのアニメーションが固定化されてしまいました。
呼び出される側のPopupViewControllerのmodalTransitionStyleを変更しても入りアニメーションは同じでした。
こちらはおそらくsegueをcustom指定することでアニメーションを調整できると思いますが、今回はとりあえずこれでOKとします。
しかし、dismiss時のアニメーションはmodalTransitionStyleで指定したとおりになるので、入りアニメーションに比較的近いアニメーションということでUIModalTransitionStyleCrossDissolveを指定してます。

PopupViewController.m

- (void)viewDidLoad
{
  [super viewDidLoad];
  // Do any additional setup after loading the view from its nib.
  self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
}

サンプルコード

次回

今回はテストしなかったポップアップ時のアニメーションについて検証してみます。

26
24
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
26
24