[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
iPhoneアプリにAboutBoxを実装
iPhoneアプリにAboutBoxを実装するためのメモ。 今回、自分のiPhoneアプリにAbou
-
-
iPhone SDK開発のネタ帳 Observerパターン
Head First デザインパターンでも2番目に紹介されているObserverパターン。使用頻度も
-
-
“I think the stainless steel looks beautiful when it wears” from The Perfect Thing
傷が付きやすいと言われている iPhone 7 ジェットブラック。ケースを付けるか迷ったら、下記
-
-
[iOS] リズムくんにiOS 3.1.3 で問題発生、修正版Submit
昨日 2012/09/07 リズムくんのサポートページ に、下記のレポートあり。 iOS3
-
-
iPhone Core Audio プログラミング (Extended Audio File Services)
発売日からずっと気になる存在だったが、Audio Queue Services を使ったプログラムを
-
-
WWDC 2010 開幕
去年と違って今年はすっかりTwitterが一般化しているので、WWDCに行く人たちの様子がよくわかる
-
-
達人出版会の本をKindleで読んでみる(Windows編)
最近話題の「当事者」の時代の電子書籍版(パブー)や、エキスパート Objective-C プログラミ
-
-
iPhone Developer Program Activation 完了
iPhone Developer ProgramのActivationの件。 木曜日の夜にメールを出
-
-
EverLearnのURLスキーム
EverLearn の URL スキームをちゃんと公開していなかったので公開しました。EverLea
-
-
[iPhone 6 Plus] カラビナ付きケースを買ってみた
iPhone5 はカラビナ付きケースに入れて腰に下げていたのだが、まだiPhone 6 Pl