[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 などは普通に呼ばれているようだ。
何度も同じことではまっている気がする。
関連記事
-
-
US Unlocked にてiPad 購入、無事入手
日本の発売まで待つか結構悩んだけれども、なるべく早く自作アプリの動作確認をしておきたいということもあ
-
-
[iPhone 開発本] iPhone/iPadゲーム開発ガイド ―Objective-Cで作る2D/3Dゲーム
今年の4月にオライリーのiPhoneゲーム開発本 iPhone Game Development (
-
-
Learn iPhone and iPad Cocos2D Game Development
洋書だけれども、ApressからCocos2d を使ってゲーム開発する本として Learn iPho
-
-
コードちゃん 1.1.0 で五度圏学習機能をサポート → 新アプリに分離しました
お知らせ ほとんど使われていないのと、1.2.0でコード進行問題を追加したため、1.2.0
-
-
iPhoneアプリ 「リズムくん」 Ver.1.1 アップデート
リズムくん Ver.1.0ではまずは8分音符までの問題でリリースしてみましたが、やはりより難しい問題
-
-
Lexical or Preprocessor issue ‘xxx.h’ file not found
NSMutableArray に要素をランダムに並び替える機能を入れようと思い、 objective
-
-
iPhone SDK勉強会
iPhone 開発の勉強会をしよう、ということになったので、それ向けにメモを書いてみる。相手はいろい
-
-
App Store レビュー中
8月13日にApp StoreにSubmitしたiPhoneアプリがまだIn Review状態だ。果
-
-
新アプリ「コードちゃん」を公開しました
速報:新 iPad 発表。Apple Pencil対応で3万7800円から - Engadget