Save 37% off PRO during our Black Friday Sale! »

そのAlertController 回転ロックできないってよ

E586b46d5b09f8109beb66bb146e4f20?s=47 tamappe
February 12, 2020

そのAlertController 回転ロックできないってよ

E586b46d5b09f8109beb66bb146e4f20?s=128

tamappe

February 12, 2020
Tweet

Transcript

  1. ͦͷAlertController ճసϩοΫͰ͖ͳ͍ͬͯΑ @tamapppe potatotips #68 (iOS/Android։ൃTipsڞ༗ձ) 2020/2/12

  2. I N T R O D U C T I

    O N Tamappe (ͨ·ͬ΃) ϞόΠϧΞϓϦΤϯδχΞ 2014೥-2019೥3݄·ͰϑϦʔϥϯεͱͯ͠׆ಈ 2019೥4݄ΑΓϨΞδϣϒʹϞόΠϧΞϓϦΤϯδχΞͱͯ͠ೖࣾ झຯ: ήʔϜ(Splatoon2)ɺےτϨɺྉཧ Twitter: https://twitter.com/tamapppe 01
  3. None
  4. 02

  5. ຊ೔ͷςʔϚ iOSͷը໘ճస੍ޚ

  6. ͓࿩͢͠Δ͜ͱ 03 - ୺຤ճసͷ࣌ͷճస੍ޚ - ViewControllerͷ֊૚ - ճసϩοΫ (͜͜Ͱ͸ճసͰ͖ͳ͍Α͏ʹ͢Δ͜ ͱ)

  7. ࠷ॳʹΫΠζ 04 ͜ͷUIViewControllerͷճసϩοΫ͸Ͳ͜Ͱ੍ޚ͢Ε͹͍͍ʁ UITabBarController ʹ৐͍ͬͯΔ UINavigationController ʹ৐͍ͬͯΔ UIViewController ʹ৐͍ͬͯΔ presentViewController

    ʹ৐͍ͬͯΔ UIAlertController (Ξϥʔτ) ͜ͷΞϥʔτ͕දࣔ͞Ε͍ͯΔ࣌ͷΈը໘͕ճస͞Εͳ͍Α͏ʹ͍ͨ͠ Ͳ͜Ͱ੍ޚ͢Ε͹͍͍ʁ ͜ΕΛղ͘ͷ͕ࠓճͷLTͷςʔϚͰ͢ɻ
  8. ← ͜ͷΞϥʔτ

  9. Ͳͩ͜ͱࢥ͍·͔͢ʁ 05 1. UITabBarController 2. UINavigationController 3. UIViewController 4. presentViewController

    5. UIAlertController
  10. ࿩͕͠ผʹͳΓ·͕͢… ୺຤ͷճసΛڐՄ͢Δํ๏Λ෮श͠·͢ 06 - Device Orientation - info.plist - ͦΕͧΕͷUIViewController

    Ϋϥε
  11. Device Orientation

  12. Info.plist

  13. info.plist 07 iPhoneͱiPadͱͰผʑʹ؅ཧ͍ͨ͠৔߹ʹΑ͘࢖͍·͢ɻ - iPad͸ճసͤ͞ͳ͍͚ͲɺiPhone͚ͩճస͍ͤͨ͞ - iPhoneͰ͸ճసͤͣ͞ʹiPad͚ͩճస͍ͤͨ͞ - iPhone͸ॎͷΈɺiPad͸ԣը໘͚ͩ ͜Μͳ৔߹ʹ࢖ΘΕ·͢ɻ

    ͨͩ͠ɺ͜Ε͸શͯͷUIViewController ʹҰׅద༻ͤ͞Δͱ͖ͷΈ
  14. ͦΕͧΕͷUIViewController Ͱ੍ޚ 08 Aը໘Ͱ͸ॎը໘ʹݻఆͯ͠ɺBը໘Ͱ͸ԣը໘͚ͩʹ͍ͨ͠ͳͲ UIViewController ୯ҐͰը໘ͷճసΛ੍ޚ͢Δ࣌ʹ࢖͍·͢ɻ extension BaseNavigationController { //

    ը໘Λճసͤ͞Δ͔Ͳ͏͔ override var shouldAutorotate: Bool { return true } // ճసํ޲ͷࢦఆ override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .all } }
  15. ΍ͬͱຊ୊Ͱ͢ 09 ͜ͷUIViewControllerͷճసϩοΫ͸Ͳ͜Ͱ੍ޚ͢Ε͹͍͍ʁ UITabBarController ʹ৐͍ͬͯΔ UINavigationController ʹ৐͍ͬͯΔ UIViewController ʹ৐͍ͬͯΔ presentViewController

    ʹ৐͍ͬͯΔ UIAlertController (Ξϥʔτ)
  16. ౴͑ 10 ͜ͷUIViewControllerͷճసϩοΫ͸Ͳ͜Ͱ੍ޚ͢Ε͹͍͍ʁ UITabBarController ʹ৐͍ͬͯΔ UINavigationController ʹ৐͍ͬͯΔ UIViewController ʹ৐͍ͬͯΔ presentViewController

    ʹ৐͍ͬͯΔ UIAlertController (Ξϥʔτ) ( <- ίί) Answer) UIAlertController
  17. ౴͑ (ίʔυ) 11 UIAlertController+Orientation.swift import UIKit extension UIAlertController { open

    override var shouldAutorotate: Bool { return false } open override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .portrait } }
  18. ͦΕͧΕͷViewController Ͱ੍ޚ͢Δ৔߹ 12 UIAlertController → UIAlertController presentViewController →UINavigaitonController UITabBarController ʹ৐͍ͬͯΔUINavigationController

    ʹ৐͍ͬͯΔUIViewController → UITabBarController
  19. Ҏ্ 13 ୺຤ͷճసΛڐ͢ͱճసϩοΫͳͲͷ੍ޚ͕େมʹͳΓ ·͢ɻ චऀ͸ճసܥͷϝιουΛॻ͘৔߹͸ExtensionͰॻ͘ ͜ͱ͕ଟ͍Ͱ͢ɻ

  20. Thank you!