iOS 6 のAuto Rotation

2,336 views

Published on

第47回 Cocoa勉強会関西 発表資料。

Published in: Technology, News & Politics
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,336
On SlideShare
0
From Embeds
0
Number of Embeds
500
Actions
Shares
0
Downloads
4
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

iOS 6 のAuto Rotation

  1. 1. iOS 6 のAuto Rotation 2012.12.01 ふじしげ ゆういち @nakiwo
  2. 2. • ふじしげ ゆういち • @nakiwo • 株式会社フィードテイラー http://feedtailor.jp/ Book+ そら案内 Slidrs
  3. 3. • ふじしげ ゆういち • @nakiwo • http://www.nakiwo.com/ 洞窟物語 めがね (Mac AppStore)
  4. 4. 今日のテーマ •iOS 6でのUIViewController Auto Rotation •iOS 6で仕様が大幅変更 •iOS 6での仕様を把握する
  5. 5. iOS 5 UIViewController - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation By default, this method returns YES for the UIInterfaceOrientationPortrait orientation only.
  6. 6. iOS 6 UIViewController - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation By default, this method returns YES for the UIInterfaceOrientationPortrait orientation only. •deprecated •呼ばれません
  7. 7. UIViewController UIViewController UIViewController UIViewController UIViewController
  8. 8. UIViewController UIViewController UIViewController UIViewController UIViewController 誰が正解?
  9. 9. UIInterfaceOrientationMask typedef enum { UIInterfaceOrientationMaskPortrait, UIInterfaceOrientationMaskLandscapeLeft, UIInterfaceOrientationMaskLandscapeRight, UIInterfaceOrientationMaskPortraitUpsideDown, UIInterfaceOrientationMaskLandscape, UIInterfaceOrientationMaskAll, UIInterfaceOrientationMaskAllButUpsideDown, } UIInterfaceOrientationMask; ※ビットマスク
  10. 10. 関係者 UIApplication UIViewController
  11. 11. 関係者 UIApplication UIViewController window.rootViewController または トップのpresentedViewController(モーダル)
  12. 12. 関係者 UIApplication UIViewController window.rootViewController または トップのpresentedViewController(モーダル)
  13. 13. 関係者 UIApplication UIViewController UIInterfaceOrientationMask window.rootViewController または トップのpresentedViewController(モーダル)
  14. 14. 関係者 UIApplication UIViewController UIInterfaceOrientationMask window.rootViewController または トップのpresentedViewController(モーダル)
  15. 15. 関係者 UIApplication UIViewController UIInterfaceOrientationMask UIInterfaceOrientationMask window.rootViewController または トップのpresentedViewController(モーダル)
  16. 16. 関係者 UIApplication UIViewController UIInterfaceOrientationMask UIInterfaceOrientationMask window.rootViewController または トップのpresentedViewController(モーダル)
  17. 17. 関係者 UIApplication UIViewController UIInterfaceOrientationMask UIInterfaceOrientationMask window.rootViewController または トップのpresentedViewController(モーダル)
  18. 18. 関係者 UIApplication UIViewController UIInterfaceOrientationMask UIInterfaceOrientationMask window.rootViewController または トップのpresentedViewController(モーダル) bit and
  19. 19. 関係者 UIApplication UIViewController UIInterfaceOrientationMask UIInterfaceOrientationMask UIInterfaceOrientationMask window.rootViewController または トップのpresentedViewController(モーダル) bit and
  20. 20. 関係者 UIApplication UIViewController UIInterfaceOrientationMask UIInterfaceOrientationMask UIInterfaceOrientationMask window.rootViewController または トップのpresentedViewController(モーダル) bit and 対応回転方向決定
  21. 21. 関係者 UIApplication UIInterfaceOrientationMask
  22. 22. UIApplication UIApplicationDelegate - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 上記メソッド未実装の時は次のメソッドが呼ばれる UIApplication - (NSUInteger)supportedInterfaceOrientationsForWindow: (UIWindow *)window
  23. 23. 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.
  24. 24. 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
  25. 25. 関係者 UIApplication UIViewController UIInterfaceOrientationMask UIInterfaceOrientationMask UIInterfaceOrientationMask window.rootViewController または トップのpresentedViewController(モーダル) bit and 対応回転方向決定
  26. 26. UIViewController UIInterfaceOrientationMask window.rootViewController または トップのpresentedViewController(モーダル)
  27. 27. UIViewController - (BOOL)shouldAutorotate AuroRotateするかどうか(default=YES) - (NSUInteger)supportedInterfaceOrientations default iPhone UIInterfaceOrientationMaskAllButUpsideDown iPad UIInterfaceOrientationMaskAll
  28. 28. UIViewController 注意点 UIViewController UIViewController UIViewController UIViewController
  29. 29. UIViewController 注意点 UIViewController UIViewController UIViewController UIViewController 聴かれるのは一番親だけ (水色)
  30. 30. UIViewController (UINavigationController,UITabBarController) 注意点 UIViewController UIViewController UIViewController UIViewController
  31. 31. Tips
  32. 32. iOS 5でPortrait専用 だったのにiOS 6で回転してしまう...
  33. 33. iOS 5でPortrait専用 だったのにiOS 6で回転してしまう... UIApplicationDelegate - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskPortrait; }
  34. 34. Navigationの子で shouldAutorotateToInterfaceOrientationを 使っていたが呼ばれない....
  35. 35. Navigationの子で shouldAutorotateToInterfaceOrientationを 使っていたが呼ばれない.... UINavigationControllerのサブクラスを作って... - (NSUInteger)supportedInterfaceOrientations { NSUInteger supportedInterfaceOrientations; = [self.topViewController supportedInterfaceOrientations]; return supportedInterfaceOrientations; }
  36. 36. iOS 5もサポートしないと...
  37. 37. 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; }
  38. 38. おまけ
  39. 39. おまけ • 複数法対応のViewControllerをモーダルで出す 時、初期方向を変えたい • 例:動画プレイヤー 縦横対応しているが、初期では横にしたい。
  40. 40. おまけ • 複数法対応のViewControllerをモーダルで出す 時、初期方向を変えたい • 例:動画プレイヤー 縦横対応しているが、初期では横にしたい。 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }
  41. 41. •View Controller Programming Guide for iOS > Supporting Multiple Interface Orientations
  42. 42. おわり

×