[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
イタリア語でレビューをいただきました
おんぷちゃん for iPad にイタリア語でレビューをいただきました。 Ottimo! O
-
-
[iPhone アプリマーケティング] Yappler.com に登録してみた
たまたま検索していて発見した、Yappler.com に試しに登録してみた。 iPhoneアプリ開発
-
-
[iOS SDK] NSUserDefaults boolForKey でNOが返ってくるとNOが格納されていたのか値が存在しなかったのかが不明
NSUserDefaults Class Reference にあるとおり、NSUserDefau
-
-
セブンイレブンでiPhoneから写真プリント
今は事前登録なしにセブンイレブンでiPhoneからプリントが行えるけれども、店の人もわかって
-
-
新アプリ「ドラムちゃん」を公開しました
2015年から作りはじめた iPad専用 ドラム譜学習アプリ ドラムちゃん を本日 2017/01/
-
-
英単語学習アプリ EverLearn Ver.1.2.5 が公開されました
2016/03/05 Updateこの記事は公開時(2013年10月)から時間が経って古い内容になっ
-
-
[iOS9] viewWillAppear で部品の位置が確定しなくなった
どうやら iOS9 から viewWillAppear では部品の位置が確定しなくなったらしく、vi
-
-
ドラムちゃんに電子ドラムiWordを接続する
ドラム譜学習アプリ「ドラムちゃん」に、安価なMIDI電子ドラム iWord を接続する方法を説明し
-
-
KickstarterでMiselu の iPad用キーボード C.24 に出資してみた
C.24 - The Music Keyboard for iPad by Miselu —
-
-
AWS IoTを利用してクラウド連携機能を追加してみた
GWに自宅待機でまとまった時間が確保できたので、AWS IoT を利用してMQTTを使った