[iOS SDK] UIDeviceOrientation ではまる
すぐURLが変更されそうだが、2013/02/16 時点だと、Supporting Multiple Interface Orientations という記事がiOS Developer Library にある。
View Controller Programming Guide for iOS: Supporting Multiple Interface Orientations
そこに、下記のようなコードがあり、UIDeviceOrientation を普通に使っている。
@implementation PortraitViewController - (void)awakeFromNib { isShowingLandscapeView = NO; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; } - (void)orientationChanged:(NSNotification *)notification { UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView) { [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self]; isShowingLandscapeView = YES; } else if (UIDeviceOrientationIsPortrait(deviceOrientation) && isShowingLandscapeView) { [self dismissViewControllerAnimated:YES completion:nil]; isShowingLandscapeView = NO; } }
このため、このコードをそのまま流用して画面回転対応コードを書いていたら、UIDeviceOrientation には UIDeviceOrientationFaceUp や UIDeviceOrientationFaceDown があるので、それに該当してしまい不具合を発生させてしまった。
typedef enum { UIDeviceOrientationUnknown, UIDeviceOrientationPortrait, UIDeviceOrientationPortraitUpsideDown, UIDeviceOrientationLandscapeLeft, UIDeviceOrientationLandscapeRight, UIDeviceOrientationFaceUp, UIDeviceOrientationFaceDown } UIDeviceOrientation;
ということで、UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
を使ったり、
– (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
を使ったりしよう。
iOS6 になって
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
がdeprecated になってしまったためにいろいろ混乱させられているが didRotateFromInterfaceOrientation などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
TestFlight を使ったベータテストについて
アプリのベータテストにご協力いただきありがとうございます。ベータテストには、AppleのTestFl
-
-
simplism 0.7mm Ultra Thin Case for iPhone 6 Plus(5.5inch)購入
Amazonを見ているとiPhone 6 Plus の筐体はそれなりに傷が付きや
-
-
[iPhone開発本] オライリー iPhoneアプリケーション開発ガイド 感想その1
面白そうだったので発売日に買ってみた。1995円と安いのもすばらしい。 しかしタイトルは一ひねりした
-
-
[Xcode] Interface Builder でControl+ドラッグでOutletが作成できない
たまにInterface Builder でUI作っているとはまるのでメモしておく。 Xco
-
-
Kickstarter で iPhone/Android で使える腕時計 Pebble に出資してみた
Kickstarter で28時間で100万ドルを調達したという Pebble E-Pape
-
-
[iOS 開発本] iOSフラットデザインの作法
iOS7で採用されたフラットデザインに関して、個人的には Windows 8のMetroのイ
-
-
[iOS SDK] WatchKitでできることできないこと 2015年3月
Apple Watch発売日(2015年4月24日)までに自作アプリの WatchKit対応
-
-
はじめてのiPhoneプログラミング
さらにiPhoneプログラミング本が出るらしい。出版ラッシュですな。 これは568ページもあるらしい
-
-
Corona SDK 調査5日目
スクリプト言語による効率的ゲーム開発を読み進めている。 そろそろソースコードを読んでみようと思って本
-
-
[iOS SDK] 物書堂の辞書アプリと連携してみた
物書堂は使い勝手のよい辞書アプリをたくさんリリースしている会社だ。 今作っている英単語学習アプリで