Skip to content

Instantly share code, notes, and snippets.

@hhyyg
Last active December 12, 2017 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhyyg/2251d5dc44cecc9e13a08f8e0f18b01d to your computer and use it in GitHub Desktop.
Save hhyyg/2251d5dc44cecc9e13a08f8e0f18b01d to your computer and use it in GitHub Desktop.
本のメモ:よくわかるAuto Layout https://www.amazon.co.jp/dp/B01HG97S7K?tag=aokj24gaw-22

AutoLayout

外接矩形

  • デバッグ中に外接矩形を表示するオプション設定ができる 

Leading: 先頭 Trailing: 末尾 Baseline(LastBaseline), FirstBaseline Multiplier: 制約の係数

Instrinsic Content Size 固有の寸法

Content Hugging Priority: 大きくなりにくさ、コンテンツに沿う優先度 Content Compression Resistance Priority: 小さくなりにくさ、コンテンツの圧縮抵抗優先度

レイアウト

  • 制約の更新
    • 制約のactiveフラグ
    • 制約の優先度変更、追加、削除、ビューの階層変更
  • フレームの更新
    • ビューのフレームが変更(回転など)
    • サブビューを追加
    • UIScrollviewのサブクラスでcontentOffsetが変更
  • レンダリングの更新
    • ビューの一部を隠している別のビューの移動・除去
    • Hiddenなビューの再表示
    • ビューを画面外までスクロールし、再び画面内に戻す
    • ビューのsetNeedsDisplay, setNeedsDisplayInRect

UIScrollViewで無限スクロール

UIStackView

  • Axis 軸
    • Horizontal, Vertical
  • Alignment 揃え方
    • Horizontal: Fill, Top, Center, Bottom
    • Vertical: Fill, Leading, Center, Trailing
  • Distribution 並べ方
  • Spacing

Resolve Auto Layout Issues

  • Update Frames
    • フレーム更新
  • Update Constraints
    • キャンバス上のフレームを元に、制約を更新
  • Add Missing Constraints
    • 足りない制約を追加
  • Reset to Suggested Constraints
    • 制約情報を削除し、キャンバス上の位置情報から制約を与える
  • Clear Constraints

UILayoutGuideの表示 “Show Layout Rectangles” Storyboardの分割 “Refactor to Storyboard….“

NSLayoutAnchor ファクトリークラスによる制約の生成 VFL文字列(あまり使わなさそう、でも読み解くときに必要)

UILayoutGuide

Auto Layout ライブラリ

  • KeepLayout
  • PureLayout

superView(親ビュー)

// Self-Sizing
tableView.estimatedRowHeight = 100.0
tableView.rowHeight = UITableViewAutomaticDimension

レイアウト崩れの主な原因

  • 曖昧
  • コンフリクト

Command + 4 “Issue Navigator”

  • 曖昧かどうか:self.view.hasAmbiguousLayout() 再帰チェック
  • Private method を用いたデバッグ
  • シンボリックブレークポイイントによりコンフリクトを捉える

サイズクラスとIB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment