[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開発のネタ帳: sonsongithub の PopupView を使ってみた
自作アプリで sonson 氏の PopupView を使わせていただいてます。 Softwar
-
-
Cocoa Design Patterns
いまさらながら最近デザインパターンにはまっており、Cocoaでどんなデザインパターンが使われているの
-
-
[IOS] iOS オープンソースライブラリ徹底活用 菊田剛著 秀和システム
ふらっと家の近くの書店に寄ったところたまたま発見した本。 最近発売されたようだ。 21章で69
-
-
[iOS SDK] iPhone/iPad はサイレントモードにしても音が鳴る
この前、iOS5 を入れた iPad2 で おんぷちゃん for iPad から音が鳴らない、ほかの
-
-
[iPhone開発本] iPad電子書籍アプリ開発ガイドブック
2010年8月23日発売らしい。3570円と高いけれども、内容は濃そうだ。 目次はImpress D
-
-
Apple Special Event 2011
2011年は iPhone 4s が発表された。 https://japanese.enga
-
-
最近読んだ本: iOS デバッグ&最適化技法 2011/06/26
発売されたことは知っていたが、とりあえず必要としてなかったのでずっと買わずにいた、iOSデバッグ&最
-
-
[iOS SDK] No identities are available for signing 問題にはまる
久しぶりに Provisioning Profileではまった。 この問題にはまると、解決までにか
-
-
Topeak Ridecase for iPhone 7 Plus は2017年1月発売
(画像はiPhone 6 Plus 用 Ridecase)7月にTopeak Ridecase fo