[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/iPad にMIDIキーボードを接続する
iPhone や iPad に MIDI キーボードが接続できると、実際のキーボードをつかって操作が
-
-
GTD用にOmniFocusを購入
半年くらいMacBookとiPhoneでOmniFocusを使っている。 なかなか良いので、紹介して
-
-
[iPhone5] 使用開始5日目の感想
au iPhone5を発売日翌日(9/22)に購入してから5日経ったので感想を書いてみる。 し
-
-
初 iPadアプリ おんぷちゃん for iPad 公開
iPadグランドオープニングに間に合わせるためしばらく格闘していたがようやく おんぷちゃん for
-
-
達人出版会の本をKindleで読んでみる(Windows編)
最近話題の「当事者」の時代の電子書籍版(パブー)や、エキスパート Objective-C プログラミ
-
-
児童手当 認定請求書申請 2024 「請求者が養育をする18歳に達する日以降の最初の3月31日までの子の数」とは?
2024年に受給していない人には手紙が届くらしい。 電子申請も可能ということで、iPhone
-
-
EverLearn 1.8.0をリリースしました
以前から、iOSから英単語をPebbleに転送できるアプリを作っていましたが、今回はPebbleの画
-
-
災害時のためのiPhone充電機器を探してみる
3/11(金)の2011年東北地方太平洋沖地震の後、宮城と岩手の親類と連絡が取れず、3/14(月)の
-
-
Beginning iPhone 3 Developmentの続編が出るらしい
iPhone開発の入門書としていま一番良いと個人的に思っている、Apressの Beginning
-
-
ITMS-90175 Legacy Language Designator
自分は自作アプリの非常に古いプロジェクトをいまだにメンテすることがあるので、ITMS-90