iOS 6 のAuto Rotation
2012.12.01
ふじしげ ゆういち
@nakiwo
• ふじしげ ゆういち
• @nakiwo
• 株式会社フィードテイラー
http://feedtailor.jp/
Book+
そら案内
Slidrs
• ふじしげ ゆういち
• @nakiwo
• http://www.nakiwo.com/
洞窟物語
めがね
(Mac AppStore)
今日のテーマ
•iOS 6でのUIViewController Auto
Rotation
•iOS 6で仕様が大幅変更
•iOS 6での仕様を把握する
iOS 5
UIViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
By default, this method returns YES for the
UIInterfaceOrientationPortrait orientation only.
iOS 6
UIViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
By default, this method returns YES for the
UIInterfaceOrientationPortrait orientation only.
•deprecated
•呼ばれません
UIViewController
UIViewController
UIViewController
UIViewController
UIViewController
UIViewController
UIViewController
UIViewController
UIViewController
UIViewController
誰が正解?
UIInterfaceOrientationMask
typedef enum {
UIInterfaceOrientationMaskPortrait,
UIInterfaceOrientationMaskLandscapeLeft,
UIInterfaceOrientationMaskLandscapeRight,
UIInterfaceOrientationMaskPortraitUpsideDown,
UIInterfaceOrientationMaskLandscape,
UIInterfaceOrientationMaskAll,
UIInterfaceOrientationMaskAllButUpsideDown,
} UIInterfaceOrientationMask;
※ビットマスク
関係者
UIApplication UIViewController
関係者
UIApplication UIViewController
window.rootViewController または
トップのpresentedViewController(モーダル)
関係者
UIApplication UIViewController
window.rootViewController または
トップのpresentedViewController(モーダル)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask
window.rootViewController または
トップのpresentedViewController(モーダル)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask
window.rootViewController または
トップのpresentedViewController(モーダル)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
window.rootViewController または
トップのpresentedViewController(モーダル)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
window.rootViewController または
トップのpresentedViewController(モーダル)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
window.rootViewController または
トップのpresentedViewController(モーダル)
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
window.rootViewController または
トップのpresentedViewController(モーダル)
bit
and
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
UIInterfaceOrientationMask
window.rootViewController または
トップのpresentedViewController(モーダル)
bit
and
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
UIInterfaceOrientationMask
window.rootViewController または
トップのpresentedViewController(モーダル)
bit
and
対応回転方向決定
関係者
UIApplication
UIInterfaceOrientationMask
UIApplication
UIApplicationDelegate
- (NSUInteger)application:(UIApplication *)application
supportedInterfaceOrientationsForWindow:(UIWindow *)window
上記メソッド未実装の時は次のメソッドが呼ばれる
UIApplication
- (NSUInteger)supportedInterfaceOrientationsForWindow:
(UIWindow *)window
UIApplication
- (NSUInteger)supportedInterfaceOrientationsForWindow:
(UIWindow *)window
The default implementation of this method returns the app’s
default set of supported interface orientations, as defined in
the UIInterfaceOrientation key of the Info.plist file.
If the file does not contain that key, this method returns all
interface orientations for the iPad idiom and returns all
interface orientations except the portrait upside-down
orientation for the iPhone idiom.
UIApplication
- (NSUInteger)supportedInterfaceOrientationsForWindow:
(UIWindow *)window
The default implementation of this method returns the app’s
default set of supported interface orientations, as defined in
the UIInterfaceOrientation key of the Info.plist file.
If the file does not contain that key, this method returns all
interface orientations for the iPad idiom and returns all
interface orientations except the portrait upside-down
orientation for the iPhone idiom.
Info.plistに
UISupportedInterfaceOri
entations有
UISupportedInterfaceOrientationsの値
Info.plistに
UISupportedInterfaceOri
entations無
iPhone
UIInterfaceOrientationMaskAllButUpsideDown
iPad
UIInterfaceOrientationMaskAll
関係者
UIApplication UIViewController
UIInterfaceOrientationMask UIInterfaceOrientationMask
UIInterfaceOrientationMask
window.rootViewController または
トップのpresentedViewController(モーダル)
bit
and
対応回転方向決定
UIViewController
UIInterfaceOrientationMask
window.rootViewController または
トップのpresentedViewController(モーダル)
UIViewController
- (BOOL)shouldAutorotate
AuroRotateするかどうか(default=YES)
- (NSUInteger)supportedInterfaceOrientations
default
iPhone UIInterfaceOrientationMaskAllButUpsideDown
iPad UIInterfaceOrientationMaskAll
UIViewController
注意点
UIViewController
UIViewController
UIViewController
UIViewController
UIViewController
注意点
UIViewController
UIViewController
UIViewController
UIViewController
聴かれるのは一番親だけ (水色)
UIViewController (UINavigationController,UITabBarController)
注意点
UIViewController
UIViewController
UIViewController
UIViewController
Tips
iOS 5でPortrait専用
だったのにiOS 6で回転してしまう...
iOS 5でPortrait専用
だったのにiOS 6で回転してしまう...
UIApplicationDelegate
- (NSUInteger)application:(UIApplication *)application
supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
Navigationの子で
shouldAutorotateToInterfaceOrientationを
使っていたが呼ばれない....
Navigationの子で
shouldAutorotateToInterfaceOrientationを
使っていたが呼ばれない....
UINavigationControllerのサブクラスを作って...
- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger supportedInterfaceOrientations;
= [self.topViewController supportedInterfaceOrientations];
return supportedInterfaceOrientations;
}
iOS 5もサポートしないと...
iOS 5もサポートしないと...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
// 今まで通りに書く
return ...;
}
- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger supportedInterfaceOrientations = 0;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait])
supportedInterfaceOrientations |= UIInterfaceOrientationMaskPortrait;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown])
supportedInterfaceOrientations |= UIInterfaceOrientationMaskPortraitUpsideDown;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft])
supportedInterfaceOrientations |= UIInterfaceOrientationMaskLandscapeLeft;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight])
supportedInterfaceOrientations |= UIInterfaceOrientationMaskLandscapeRight;
return supportedInterfaceOrientations;
}
おまけ
おまけ
• 複数法対応のViewControllerをモーダルで出す
時、初期方向を変えたい
• 例:動画プレイヤー
縦横対応しているが、初期では横にしたい。
おまけ
• 複数法対応のViewControllerをモーダルで出す
時、初期方向を変えたい
• 例:動画プレイヤー
縦横対応しているが、初期では横にしたい。
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
•View Controller Programming
Guide for iOS
> Supporting Multiple Interface
Orientations
おわり

iOS 6 のAuto Rotation