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

No Story, No Board

No Story, No Board

Elvis Shi

June 23, 2017
Tweet

More Decks by Elvis Shi

Other Decks in Programming

Transcript

  1. override init() { super.init() emplyedBy = "MAGES. 5pb. Game div"

    job = "iOS Developer" twitter = "@lovee" qiita = "@lovee" github = "el-hoshino" additionalInfo = "ʮAuto Layout ઈରࡴ͢ϚϯʯͰ͢" class Speaker: Developer { } }
  2. ͦΕͰ΋ Auto Layout ࢖͍͍ͨํ PureLayout macOS / iOS ྆ํͰར༻Ͱ ͖Δ

    Swift / Objective-C ྆ํͰ ར༻Ͱ͖Δ AutoLayout ੍໿Λ؆ܿʹɺ ͔ͭൺֱతʹ෼͔Γ΍͢ ͘ॻ͚Δ ͔ͳΓॆ࣮͍ͯ͠Δࢿྉ
  3. ͦΕͰ΋ Auto Layout ࢖͍͍ͨํ SnapKit macOS / iOS / tvOS

    શ෦ར ༻Ͱ͖Δ Swift ͷߏจಛ௃Λ࠷େݶ ʹҾ͖ग़͍ͯ͠Δ গ͠௕͘ͳΔ͕ɺඇৗʹ ෼͔Γ΍͍͢จ๏ ඇৗʹॆ࣮͍ͯ͠Δެࣜ ࢿྉ
  4. UIView / UIViewController ͷϥΠϑαΠΫϧΛཧղ͢Δ UIViewController UIView loadView() viewDidLoad() viewWillAppear() viewWillLayoutSubviews()

    layoutSubviews() viewDidLayoutSubviews() viewDidAppear() layout runloop viewWillDisappear() viewDidDisappear() layoutIfNeeded() Needs layout? sleep viewWillLayoutSubviews() layoutSubviews() viewDidLayoutSubviews() Disappear? no yes yes no Needs layout?
  5. UIView / UIViewController ͷϥΠϑαΠΫϧΛཧղ͢Δ ͸Ͳ͏΍ͬͯ൑ఆ͍ͯ͠Δͷ͔ʁ Needs layout? setNeedsLayout() Λݺͼग़ͨ͠ σόΠε͕ճసͨ͠

    ࢠϏϡʔΛ௥Ճ΍࡟আΛͨ͠ ʢUIScrollView Ͱ͋ΔࢠϏϡʔʣ͕εΫϩʔϧͨ͠ ࣗ෼ͷࢠϏϡʔͷ frame ΍ transform ͳͲ͕มߋ͞Εͨ ͳͲͳͲ…
  6. UIView / UIViewController ͷϥΠϑαΠΫϧΛཧղ͢Δ ͸Ͳ͏΍ͬͯ൑ఆ͍ͯ͠Δͷ͔ʁ Needs layout? setNeedsLayout() Λݺͼग़ͨ͠ σόΠε͕ճసͨ͠

    ࢠϏϡʔΛ௥Ճ΍࡟আΛͨ͠ ʢUIScrollView Ͱ͋ΔࢠϏϡʔʣ͕εΫϩʔϧͨ͠ ࣗ෼ͷࢠϏϡʔͷ frame ΍ transform ͳͲ͕มߋ͞Εͨ ͳͲͳͲ… ࣗ෼ͷ frame ΍ transform Λมߋ͢Ε͹
 ਌ͷ layoutSubviews() ΋ݺ͹ΕΔʂ ࣗ෼ͷ frame ΍ transform ͸
 ඞͣ਌ʹมߋͯ͠΋Β͓͏ʂ
  7. ϨΠΞ΢τΛઃఆ͢ΔϓϩύςΟʔΛཧղ͢Δ view.frame = CGRect(x: 0, y: 0, width: 200, height:

    200) view.transform = view.transform.rotated(by: .pi / 4) view.frame.size.width = 100
  8. ϨΠΞ΢τΛઃఆ͢ΔϓϩύςΟʔΛཧղ͢Δ view.frame = CGRect(x: 0, y: 0, width: 200, height:

    200) view.transform = view.transform.rotated(by: .pi / 4) view.frame.size.width = 100 Α͘஌ΒΜ͕ frame.size.width Λ൒෼ʹͨ͠Β
 ෯΋ߴ͞΋ཱͪҐஔ΋શ͕ͯมΘͬͨ"
  9. ϨΠΞ΢τΛઃఆ͢ΔϓϩύςΟʔΛཧղ͢Δ view.bounds.size = CGSize(width: 100, height: 100) view.center = CGPoint(x:

    base.bounds.midX, y: base.bounds.midY) view.layer.anchorPoint.y = 0 Α͘஌ΒΜ͕ layer.anchorPoint Λมߋͨ͠Β
 ࣗ෼ͷ৔ॴ͕มΘͬͨ"
  10. let titleViewLayout = Layout .makeCustom(x: { _ in 0 },

    y: { _ in 0 }, width: { $0.width }, height: { _ in 60 }) baseView.addSubview(titleView, constantLayout: titleViewLayout) NotAutoLayout 1.0
  11. baseView.nal.setupSubview(titleView) { $0 .setDefaultLayout { $0 .pinTopCenter(to: baseView, s: .topCenter)

    .setWidth(to: baseView, s: .width) .setHeight(to: 60) } .addToSelf() .commit() } NotAutoLayout 2.0ʢԾʣ