[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
[Apple Watch] 2017年の冬休みの宿題はwatchOSアプリ開発
自分はPebble初代のころからスマートウォッチはPebble派だったが、2016年の年末は Peb
-
-
[iPhone SDK] 日時のローカライズ
自分でも何度か調べてしまったので記録しておく。 Objective-Cで日時を表示したい場合、単純
-
-
iPhone開発のネタ帳: UIPopoverController に UIPickerView をいれる
iPad から追加された部品の一つに、UIPopoverController がある。 iPadが
-
-
Reject 履歴 おんぷちゃん 1.9.1
iOS14からおんぷ先生と接続できない の修正のため、久しぶりにおんぷちゃんを更新したとこ
-
-
The file XXX couldn’t be opened because you don’t have permission to view it.
The file XXX couldn't be opened because you d
-
-
EverLearnのURLスキーム
EverLearn の URL スキームをちゃんと公開していなかったので公開しました。EverLea
-
-
はじめてのiPhoneプログラミング 正誤表
発売されてからすぐ はじめてのiPhoneプログラミング を購入し、必要に応じて少しずつ読み進めてい
-
-
見たかった映画「ソーシャル・ネットワーク」を見る複数の方法
かなり見たかったけれどもふたごが小さくてとても見に行けなかった映画、「ソーシャル・ネットワーク」がも
-
-
Xcodeの Console出力をクリアするキーバインド
いつも忘れるので、メモとして残しておく。Command(⌘)+ Kその他はこちら。 Menu Com
-
-
[iOS SDK] 消音モードでも音を再生する対応を入れました
昔、 iPhone/iPad はサイレントモードにしても音が鳴る という記事を書いたけれども