[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
[iOS SDK] Studyplus の API を利用してみる
学習管理プラットフォーム「Studyplus」がAPIを公開——外部教材アプリとの連携を強化 | T
-
-
おんぷちゃん for iPad リアル鍵盤で回答
おんぷちゃん for iPad は五線譜上に表示される音符をスクリーン上のキーボードや、USBやB
-
-
3/8(木)深夜はiPad3の発表?
3/7(水)(日本時間3/8(木)深夜) にAppleのプレスイベントがあり、iPad3 が発表
-
-
EverLearn 1.8.1 を公開しました
EverLearn 1.8.1 を本日公開しました (2016/10/27)単語検索ページで単語をハ
-
-
[iOS SDK] Pebble腕時計対応iOSアプリを作る
英単語学習アプリ WordLearnをリリースしましたに書いたけれども今Pebble腕時計対応iOS
-
-
[iPhone SDK] sqlite 学習中。FMDB を知る。
SQLite入門 第2版西沢 直木 翔泳社 2009-05-19売り上げランキング : 17582
-
-
謎のエラー iPhone/iPod Touch: application executable is missing a required architecture
リズムくん Ver.1.1の App Store への Submit の際に、謎のエラー iPhon
-
-
はじめてのiPhoneプログラミング
さらにiPhoneプログラミング本が出るらしい。出版ラッシュですな。 これは568ページもあるらしい
-
-
Apple Developer Program 更新2016
そろそろ期限が切れるので、Apple Developer Program - Apple Devel
-
-
おんぷちゃん for iPad 2.0.0リリース
あけましておめでとうございます。今年もよろしくお願いします。 2022年8月にはだいたい完成