[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
英単語学習アプリ EverLearn 1.4.0 を公開しました
ようやく、iOS7 に対応した EverLearn 1.4.0 を公開しました。 i
-
-
[iOS SDK] iTunes Connect ではまる
iOS8リリースに合わせてiTunes Connect のUIが大幅に変わっており、下記のページの方
-
-
iPhone向け有償・無償フレームワーク
かごおた さんで、iPhone アプリ開発で使用できる有償・無償フレームワークが紹介されていた。 有
-
-
達人出版会の本をKindleで読んでみる(Windows編)
最近話題の「当事者」の時代の電子書籍版(パブー)や、エキスパート Objective-C プログラミ
-
-
リズムくんにくまモン画像を利用させていただきました
熊本県さまから許諾をいただけたので、リズムくん バージョン1.6で、くまモン画像を表示
-
-
Olympus Camera Kit (SDK)を製品版に移行
発売が延期されていた OLYMPUS AIR A01も2015/3/25(水)についに発売された。
-
-
さらに薄いiPhoneケース SwitchEasy Nude Ultra Clear
以前 eggshell for iPhone クリアを購入したが、Homeボタンを押す際などに力が入
-
-
無料版アプリの効果について
最近いくつかiPhoneアプリの無料版の提供に関してのブログが上がって、考えさせられている。 fla
-
-
[iOS SDK] QuickDialog を使ってみた
iOS オープンソースライブラリ徹底活用 菊田剛著 秀和システム | DevCafeJp で紹介さ