はじめに
タイトル通り。なんかポップオーバーがおかしい!?
同じ境遇の人の一助になれば幸いです。
現象
iPhone 画面横向きでポップオーバー表示すると下記のように表示がおかしい。
発生したソース
発生した環境
- 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 でとんで一番上にあった!!と思って実装したら違うやつだった...
ちゃんと 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 では動作していたので気づくのが遅れてしまった...
さいごに
雰囲気で実装するのはやめよう!