[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
Flurryでアプリ利用状況解析
ブログには書く機会がなかったが、昔からアプリで Flurry をアプリに組み込んで、利用状
-
-
App Store の Kids Category にアプリを公開する その2
Kids Category でアプリを公開してもらうために Submit したところ、見事に Rej
-
-
Apple Special Event 2012
2012年は下記が発表された。 iPhone 5iPod touchiPod nano
-
-
[iOS9] AVSpeechSynthesizer の再生スピードがおかしい
iPhone 6 Plus を iOS9 にアップデートして自作アプリをXcode7 から転送したと
-
-
Objective-C 2.0のプロパティで再びはまる
Objective-C 2.0のプロパティに関してはまったことがあり、これはちょっと詳しく知っておく
-
-
ようやくAppStore に Submit
@ITの 日本人がつまずかないためのiPhone開発ポイント を読みながらAppStoreにアプリ公
-
-
iPhoneアプリ おんぷちゃんアップデート 2010年6月
ユーザレビューなどで複数の方から要望があった機能に対応してみました。 以下、その説明です。 これま
-
-
iPhoneアプリ おんぷちゃん開発日記 音楽理論学習本 Practical Theory Complete
おんぷちゃん開発のために多少の音楽理論が必要となり、良い本を探していたところ下記の本を発見しました。
-
-
iOS 16 GM版アップデート
遅ればせながら iPhone 11 Pro Maxを iOS16 GM版にアップデートを行う。
-
-
[iPhone開発のネタ帳] loadView, viewDidLoad と viewDidUnload 2011/08/12
拙作のiPadアプリ タッチ!にほんちず や タッチ!ヨーロッパ地図でUIWebViewContro