LoginSignup
3
3

More than 3 years have passed since last update.

iPhone 横向きでポップオーバー表示するとこわれた\(^o^)/

Posted at

はじめに

タイトル通り。なんかポップオーバーがおかしい!?

同じ境遇の人の一助になれば幸いです。

現象

iPhone 画面横向きでポップオーバー表示すると下記のように表示がおかしい。

横はなんかおかしい
landscape

縦は普通
portrait

発生したソース

発生した環境

  • Xcode10.2.1 iOS12.2(シミュレータ)

発生しなかった環境

  • Xcode10.2.1 iOS10.1.1(実機)
  • Xcode10.1 iOS10.1.1(実機)
  • Xcode10.1 iOS12.1(シミュレータ)

原因

デリゲートが間違っていた。

これじゃなくて

extension PrefectureListViewController: UIPopoverPresentationControllerDelegate {
    func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
        return .none
    }
}

こっち

extension PrefectureListViewController: UIPopoverPresentationControllerDelegate {
    func adaptivePresentationStyle(for controller: UIPresentationController,
                                   traitCollection: UITraitCollection) -> UIModalPresentationStyle {
        return .none
    }
}

iPhone でポップオーバーを表示するには adapt~ のやつで .none 返さないといけないということだけ覚えていて Cmd + Ctr + J でとんで一番上にあった!!と思って実装したら違うやつだった...
delegate

ちゃんと Developer にも iOS 8.3 以降は adaptivePresentationStyle(for:traitCollection:) 使おうみたいなことが書いてある。

In iOS 8.3 and later, use the adaptivePresentationStyle(for:traitCollection:) method to handle all trait changes instead of this method. If you do not implement that method, you can use this method to change the presentation style when transitioning to a horizontally compact environment.

今回は Xcode10.1 では動作していたので気づくのが遅れてしまった...

さいごに

雰囲気で実装するのはやめよう!

3
3
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
3
3