[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。

関連記事

no image

fitbit 日本語版を買ってみた

2013年3月に発売された fitbit ソフトバンクBB、Bluetooth 4.0接続の

記事を読む

no image

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

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

記事を読む

App Bundle は公開後は追加・削除できない

App Storeには App Bundleという仕組みがあり、複数のアプリをまとめてお得な値段で

記事を読む

no image

[iTunes Connect] Price End Date には安売りの終わる次の日を入れるべき

App Store では、ランキングに現れないアプリは存在しないも同然、という話がある。 App

記事を読む

no image

iPhoneアプリ 「リズムくん」 Ver.1.1 アップデート

リズムくん Ver.1.0ではまずは8分音符までの問題でリリースしてみましたが、やはりより難しい問題

記事を読む

no image

HTML5+CSS3で作る 魅せるiPhoneサイト

iPhone向けWebページの実例を使って、CSS+HTML5の使い方を説明してくれる本。 CS

記事を読む

[iOS SDK] アプリを起動しない 3D quick action は実現できるか

iPhone 6s / iPhone 6s Plus から 3D Touch 機能が搭載されたが、搭

記事を読む

iPhone6, Xperia, Galaxy Note サイズ比較

  iPhone6 Plus は一体どれくらい大きいのか想像ができなかったの

記事を読む

no image

林信行氏 iPhoneの衝撃 セミナー 2009/10/07@代々木 に参加してきた

いまさらながら、2009/10/07(水)に行われた、林信行氏 iPhoneの衝撃 セミナーのレポ

記事を読む

EverLearn 1.8.1 を公開しました

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

記事を読む

Message

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

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

ポモドーロテクニック用物理タイマーならTime Timer

会社ではなかなか自由に時間を使えないが、家で読書や作業をする

DELL 32インチディスプレイ U3223QE 購入

Dell U3223QE は解像度 3840x216

WWDC 2023 Vision Pro発表

2023/6/5 (日本時間 2023/06/06 2AM)のWWD

M1 MacBook Air を Venturaにアップデートする

M1 MacBook Air を macOS Montere

iOS16でaurioTouch の inBufferFramesが1になる

https://developer.apple.com/librar

→もっと見る

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