[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
Photoshop のバッチ処理でiOSアプリアイコンを一括作成する
毎回苦労しているiOSのアプリアイコン作成。今回はPhotoshopのバッチで作成してみる。前回は
-
iPhone アプリアイコン
iphoneアプリで稼げるのか さんと同様、自分もアイコンを作るのはつらい。 今度アプリを公開すると
-
iPhoneアプリビジネス本 The Business of iPhone App Development
iPhoneアプリを売るための情報が詰まった本。 ここまでやるか、というくらいの情報が詰まっている。
-
iPhone SDK勉強会
iPhone 開発の勉強会をしよう、ということになったので、それ向けにメモを書いてみる。相手はいろい
-
TestFlight を使ったベータテストについて
アプリのベータテストにご協力いただきありがとうございます。ベータテストには、AppleのTestFl
-
おんぷちゃん for iPad 1.3.3 Submit
今回は紅白歌合戦を見ながらSubmit。 相変わらずうちの娘が譜読みに苦労していて新しい曲を弾く
-
[iPhone開発本][洋書] iPhone 3D Programming
たまたまApp Storeで O'reilly Media で検索したら、600円の本がわんさか表示
-
[iOS SDK] No identities are available for signing 問題にはまる
久しぶりに Provisioning Profileではまった。 この問題にはまると、解決までにか
-
新アプリ「ドラムちゃん」を公開しました
2015年から作りはじめた iPad専用 ドラム譜学習アプリ ドラムちゃん を本日 2017/01/
-
UIScrollView の上で UIView を動かしたい
今作っているiPadアプリで、画面をピンチインアウトで拡大縮小して、さらにその上でドラッグで部品を動