[iOS SDK] UIDeviceOrientation ではまる

公開日: : iPad, iPhone

すぐ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

記事を読む

no image

3/8(木)深夜はiPad3の発表?

3/7(水)(日本時間3/8(木)深夜) にAppleのプレスイベントがあり、iPad3 が発表

記事を読む

EverLearn 1.8.1 を公開しました

EverLearn 1.8.1 を本日公開しました (2016/10/27)単語検索ページで単語をハ

記事を読む

no image

[iOS SDK] Pebble腕時計対応iOSアプリを作る

英単語学習アプリ WordLearnをリリースしましたに書いたけれども今Pebble腕時計対応iOS

記事を読む

no image

[iPhone SDK] sqlite 学習中。FMDB を知る。

SQLite入門 第2版西沢 直木 翔泳社 2009-05-19売り上げランキング : 17582

記事を読む

no image

謎のエラー iPhone/iPod Touch: application executable is missing a required architecture

リズムくん Ver.1.1の App Store への Submit の際に、謎のエラー iPhon

記事を読む

no image

はじめてのiPhoneプログラミング

さらにiPhoneプログラミング本が出るらしい。出版ラッシュですな。 これは568ページもあるらしい

記事を読む

Apple Developer Program 更新2016

そろそろ期限が切れるので、Apple Developer Program - Apple Devel

記事を読む

おんぷちゃん for iPad 2.0.0リリース

あけましておめでとうございます。今年もよろしくお願いします。 2022年8月にはだいたい完成

記事を読む

Message

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Break Back 22巻まで読了

テニス漫画と言えば、ベイビーステップスだと思っていたし、全巻持ってい

TORRAS iPhone 16 Pro Max用ケース

自分はiPhoneはケースを付けない派で、iPhone 12

iPhone 16 Pro Max 購入

iPhone 16 Pro Max 256GB 189000

Ember Mug 2のACアダプタをUSB Type-Cに変えてみた

冬になると活躍する Ember Mug 2 の充電器は付属のACアダ

Wi-Fi6Eルータ TP-Link AXE5400購入

Wi-Fi6E を試してみたくなり、TP-Link AXE5

→もっと見る

  • 2013年2月
     123
    45678910
    11121314151617
    18192021222324
    25262728  
PAGE TOP ↑