iOS8でinterfaceOrientaionがdeprecatedになったんだけど代わりのプロパティが分からない
間違ってたのでいろいろ追記
Xcode6でUIViewController
のinterfaceOrientation
プロパティを使うとiOS 8.0からdeprecatedですよのwarningがでます。
でも、代わりに判断できるプロパティがiPadだと分からないって話です。誰か教えて
※ 追記1 statusBarOrientation
でOK
なんかUIViewController
のプロパティでなんとかしなきゃいけないという思いにとらわれてしまっていた。statusBarOrientation
を使って以下のようにやる。
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
ios - Different ways of getting current interface orientation? - Stack Overflow
公式のReferenceとか、Stackoverflow見ると、
viewWillTransitionToSize:withTransitionCoordinator:
とかtraitCollection
を使えと書いてありました。
ios8 - How to know current interfaceOrientation in extension of iOS 8? - Stack Overflow
※ 追記2 このStackOverflowは、App Extensionsの話でした。App Extensionsでは、[UIApplication sharedApplication]
がとれないからどうすればいいですか?という話でした
ただ、iPadだと実際に、そこで縦なのか横なのかって判断できるプロパティがないんです。
UIViewControllerでtraitCollectionのプロパティの値がiPadが縦だろうが、横だろうが変わりません。
一番それっぽいプロパティのhorizontalSizeClass
もverticalSizeClass
も縦だろうが横向きだろうが、どっちにしろ、UIUserInterfaceSizeClassRegular
になっちゃいます。
NSLog(@"%d", self.traitCollection.horizontalSizeClass); // => 2 NSLog(@"%d", self.traitCollection.verticalSizeClass); // => 2
うーん。そもそも向きというものを捉えてアプリを作ろうという概念自体が間違ってるんだとは思うんだけど、とりあえずこんな感じでviewのサイズで判断するようにして回避。
※ 追記3 下のコード間違い。 statusBarOrientation
を使う
if (CGRectGetWidth(self.view.frame) > CGRectGetHeight(self.view.frame)) { // 横向き } else { // 縦 }