[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 SDK] GPX Format で位置情報を出力
今公開している Log Locations は割り切りでエクスポート機能を入れていなかったのだけれど
-
-
US Unlocked にてiPad 購入、無事入手
日本の発売まで待つか結構悩んだけれども、なるべく早く自作アプリの動作確認をしておきたいということもあ
-
-
[iPhone6plus] 買うかかなり悩み中
9/19 に発売されてからiPhone6Plusを買おうか、買うならいつ買おうか、キャリアは
-
-
Macでコマンドラインで一括オーディオフォーマット変換 afconvert
iOSアプリの場合、効果音のフォーマットは caf がよいらしい。 ダウンロードしたファイルはca
-
-
Clime もうすぐ発送?
自分以外に注目している人を見たことがない Clime だが、メールでせかしていたらもうすぐ発送してく
-
-
iPhone OS 3.0 GM Seed vs Final version
iPhone OS 3.0 が6月18日(木)より公開されているが、自分はiPhone Develo
-
-
iPhone OS 4.0 のマルチタスク対応
iPhone OS 4.0 でマルチタスク対応される、ということでWindowsやMacOS Xの
-
-
Pebble Time 届いた。これはいいものだ
Pebble Time 発表されたのでさっそく出資 | tokentoken.com で 2015
-
-
ドラムちゃんに電子ドラムiWordを接続する
ドラム譜学習アプリ「ドラムちゃん」に、安価なMIDI電子ドラム iWord を接続する方法を説明し
-
-
4年ぶりにLogLocationsをアップデート
4年ぶりにLogLocationsのアップデート版を作成中。3年間更新していなかったので、画面がフラ