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

徐々に増えているSwiftUI Anchor関連API

Avatar for tokizo tokizo
October 13, 2025
15

徐々に増えているSwiftUI Anchor関連API

Avatar for tokizo

tokizo

October 13, 2025
Tweet

Transcript

  1. rotation3DEffect (_:axis:anchor:anchorZ:perspective:) • iOS 13.0+ • Viewを指定した軸を中心に3次元で回転 • 回転の中心をAnchorで指定 5

    https://developer.apple.com/documentation/SwiftUI/Vie w/rotation3DEffect(_:axis:anchor:anchorZ:perspective:)
  2. • 左: 与えられた領域の中央寄せ • 右: gridCellAnchor を使って 全体の中央寄せ ◦ 🟥

    .gridCellAnchor(.bottomLeading) ◦ 本API登場前は数ステップ必要だった i. セル内の要素のサイズ取得 ii. セルのサイズ取得 iii. セルの内側の端まで要素をoffset移動 gridCellAnchor(_:) 8
  3. ViewAlignedScrollTargetBehavior (limitBehavior:anchor:) • iOS 26.0+ ◦ Anchorなし版はiOS 17.0+ • スクロール要素の端を所定の位置で停止できる

    ◦ scrollTargetBehavior(_:) に渡して使用 • スクロールする要素の止まる位置をAnchorで指定 9 https://developer.apple.com/documentation/swiftui/view alignedscrolltargetbehavior/init(limitbehavior:anchor:)
  4. まとめ • 3つのAnchor関連のAPIを紹介した ◦ rotation3DEffect ◦ gridCellAnchor ◦ ViewAlignedScrollTargetBehavior •

    Anchorを受け取るAPIが増えている • AnchorはUnitPointで値を指定することでより細やかに 位置系を制御できる 19