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

Auto Layout Tips

Auto Layout Tips

USAMI Kosuke

November 30, 2015
Tweet

More Decks by USAMI Kosuke

Other Decks in Programming

Transcript

  1. UIKit σβΠϯύλʔϯͱ Auto Layout → UIScrollView ͱ Auto Layout →

    UITableView ͱ Auto Layout → UICollectionView ͱ Auto Layout → ͜ΕΒͷ૊Έ߹Θͤ͸Ҋ֎͍ͨ΁Μ
  2. ͏·͍͔͘ͳ͍ύλʔϯ → UIScrollView ͷத਎ͷ View ͷαΠζ͕ Auto Layout Ͱܾ·Βͳ͍ →

    contentSize ΛίʔυͰઃఆ͢Δඞཁ͕ग़ͯ͘Δ → ద੾ͳ contentSize ΛͲ͏༩͑Δ͔೉͘͠ͳΔ
  3. Content View → ·ͣ UIScrollView ͷ಺ଆʹ Content View Λ࡞Δ →

    UIScrollView ͱ Content View ͱͷ্Լࠨӈͷ֤ล ʹ੍໿Λఆٛ͢Δ → ͜ΕͰ contentSize = Content View ͷαΠζͱͳ Δ
  4. ͏·͍͘͘ύλʔϯ → Content View ͷαΠζΛ UIScrollView ͷ ֎ଆ ʹ ͋Δཁૉ͔Βܾ·ΔΑ͏ʹ͢Δ

    → ྫ͑͹࣍ͷΑ͏ͳ֊૚ͷͱ͖ → (1) UIView - (2) UIScrollView - (3) Content View → (3) ͷαΠζ͕ (1) ͔Βܾ·ΔΑ͏ʹ͢Δ → ʢྫ͑͹ɺ෯͕౳͍͠ͱ͔ʣ
  5. UIScrollView & Auto Layout → ͜ΕͰ Auto Layout ͚ͩͰ׬݁͢Δ →

    contentSize ΛίʔυͰઃఆ͢Δඞཁ͕ͳ͘ͳΔ
  6. Self Sizing Cell (iOS 8) → tableView:estimatedHeightForRowAtIndexPath: Ͱ Ծͷߴ͞Λฦ͢ →

    tableView:heightForRowAtIndexPath: Ͱ UITableViewAutomaticDimension Λฦ͢ → ͜ΕͰ Auto Layout Ͱܾ·Δߴ͕͞ Cell ͷߴ͞ʹ
  7. ஫ҙ : Storyboard ্ͷઃఆ → Storyboard ্Ͱ͸ UITableViewCell ͷߴ͞ೖྗཁ →

    Cell ͷߴ͞ͱ Content View ͷߴ͞Λ੔߹ͤ͞Δ → Content View ͷϨΠΞ΢τΛ૊Έͳ͕ΒɺͦΕʹ ͋Θͤͯ Cell ͷߴ͞Λௐ੔ɾɾɾʢਖ਼௚ͩΔ͍ʣ
  8. Self Sizing Cell (iOS 8) → estimatedItemSize ʹԾͷαΠζΛฦ͢ ʢUISizeZero Ҏ֎ʣ

    → itemSize ͸ઃఆ͠ͳͯ͘ྑ͍ → ͜ΕͰ Auto Layout ͷαΠζ͕ Cell αΠζʹ