Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ユニバーサルアプリの理想と現実: Yahoo! JAPAN MeetUp #2

kazuhiro4949
September 08, 2016

ユニバーサルアプリの理想と現実: Yahoo! JAPAN MeetUp #2

Yahoo! JAPAN MeetUp #2 (iOS) の時の発表資料です。
http://yj-meetup.connpass.com/event/38348/

kazuhiro4949

September 08, 2016
Tweet

More Decks by kazuhiro4949

Other Decks in Technology

Transcript

  1.  4J[F$MBTT w εΫϦʔϯαΠζͷҧ͍Λந৅Խͨ͠΋ ͷ w ෯ͱߴ͞ͷαΠζʹ3FHVMBS $PNQBDU ͷछྨͷΧςΰϦΛఆٛ w

    4UPSZCPBSE΍"TTFUT$BUBMPHͰ4J[F $MBTT୯Ґͷมߋ͕Մೳ w J04ҎલͰ͸࢖͑ͳ͍ ग़య: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITraitCollection_ClassReference/
  2. 6*$PMMFDUJPO7JFX'MPX-BZPVUΛ࢖ͬͯɺEFMFHBUF಺Ͱ෼ذͤ͞Δ ॳڃ  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath

    indexPath: NSIndexPath) -> CGSize { switch (indexPath.section, indexPath.item) { case (0, 0) where traitCollection.userInterfaceIdiom == .Phone: return CGSize(width: aWidth, height: aHeight) case (0, 0) where traitCollection.userInterfaceIdiom == .Pad: return CGSize(width: aWidth / 2, height: aHeight) .. .. .. } }
  3. 6*$PMMFDUJPO7JFX'MPX-BZPVUΛ࢖ͬͯɺEFMFHBUF಺Ͱ෼ذͤ͞Δ ॳڃ  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath

    indexPath: NSIndexPath) -> CGSize { switch (indexPath.section, indexPath.item) { case (0, 0) where traitCollection.userInterfaceIdiom == .Phone: return CGSize(width: aWidth, height: aHeight) case (0, 0) where traitCollection.userInterfaceIdiom == .Pad: return CGSize(width: aWidth / 2, height: aHeight) .. .. .. } } J1IPOFͰ͋Ε͹͋Δ෯ΛऔΓɺJ1BEͰ͋Ε͹J1IPOFͷ෯ͷ൒෼ʹ͢Δ
  4. 6*$PMMFDUJPO7JFX'MPX-BZPVUΛܧঝͯ͠ɺϨΠΞ΢τΫϥε಺Ͱ෼ذͤ͞Δ தڃ  class GridLayout: UICollectionViewFlowLayout { enum DisplayMode {

    case TwoColumns = 2 case FourColumns = 4 func estimatedWidth(viewWidth: CGFloat, space: CGFloat) -> CGFloat { return CGFloat(Int(viewWidth - space) /rawValue) } .. .. } .. .. }
  5. 6*$PMMFDUJPO7JFX'MPX-BZPVUΛܧঝͯ͠ɺϨΠΞ΢τΫϥε಺Ͱ෼ذͤ͞Δ தڃ  class GridLayout: UICollectionViewFlowLayout { enum DisplayMode {

    case TwoColumns = 2 case FourColumns = 4 func estimatedWidth(viewWidth: CGFloat, space: CGFloat) -> CGFloat { return CGFloat(Int(viewWidth - space) /rawValue) } .. .. } .. .. } J1IPOFͰ͋Ε͹ྻΛऔͬͯɺJ1BEͰ͋Ε͹ྻΛऔΔΑ͏ʹ -BZPVUΫϥε಺ͰFOVNΛ࡞Δ
  6. J1IPOF༻ͱJ1BE༻ͷϨΠΞ΢τΫϥεΛ࡞ͬͯ੾Γସ͑Δ ্ڃ  class UICollectionViewController { override func viewDidLoad() {

    super.viewDidLoad() if traitCollection.userInterfaceIdiom == .Pad { collectionView?.collectionViewLayout = SectionSplitLayout(delegate: self) } else { collectionView?.collectionViewLayout = UICollectionViewFlowLayout() } } } ͜͜Ͱ͸ۮ਺ηΫγϣϯΛࠨ΁ح਺ηΫγϣϯΛӈ΁ฒ΂ΔϨΠΞ΢τΫϥεΛ࡞੒ J1BEͷ͚࣌ͩͦͷಠ࣮ࣗ૷ͨ͠ϨΠΞ΢τΫϥεΛೖΕΔ
  7. 7JFX$POUSPMMFS͔Βʮ΋͠J1BEͳΒʯͱ͍͏෼ذΛ੾Γ཭͢  enum LayoutContext { case DefaultScreen case WideScreen init(traitCollection:

    UITraitCollection, size: CGSize) { if traitCollection.horizontalSizeClass == .Regular && size.width >= size.height { self = .WideScreen } else { self = .DefaultScreen } } var navigationBarTranslucent: Bool { switch self { case .DefaultScreen: return true case .WideScreen: return false } } }