GeometryReaderの基本
利用可能なスペースを測定してコンテンツのサイズを決めます。
「GeometryReaderの基本」はCoddyKit上の無料SwiftUI Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSwiftUI Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 SwiftUI Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Measuring Space
Sometimes a view needs to know how big its slot is. GeometryReader hands you the exact size and position of the space it occupies. 📐
It Is a Container
A GeometryReader is a view whose body is a closure receiving a proxy that describes the available space.
GeometryReader { proxy in
Text("Hi")
}The Proxy
That closure parameter is a GeometryProxy. It carries the size, safe-area insets, and frame of the reader.
GeometryReader { proxy in
let w = proxy.size.width
Color.blue.frame(width: w)
}Reading the Size
The most common move is proxy.size, a CGSize giving you the width and height you can fill.
GeometryReader { proxy in
Text("\(proxy.size.width)")
}Half the Width
Use the measured width for proportional sizing, like making a bar exactly half of the available width.
GeometryReader { proxy in
Color.green
.frame(width: proxy.size.width / 2)
}It Fills by Default
A GeometryReader greedily takes all the space its parent offers, so its children align to the top-left unless you center them.
Centering Content
Because content pins top-left, wrap it or add a frame with alignment to center children inside the reader.
GeometryReader { proxy in
Text("Center")
.frame(width: proxy.size.width,
height: proxy.size.height)
}Global Coordinates
Ask for a view position in the window with proxy.frame(in: .global), handy for scroll effects and overlays.
let f = proxy.frame(in: .global)
Text("\(f.minY)")Safe Area Insets
The proxy also exposes safeAreaInsets, so you can respect notches and home indicators in custom layouts.
let top = proxy.safeAreaInsets.topUse It Sparingly
A GeometryReader changes layout behavior, so reach for it only when you truly need measurements, not as a default wrapper. ⚠️
Scroll-Driven Effects
Combined with a ScrollView, reading each item frame lets you build parallax and fade effects tied to scroll position.
Quick Check
Recall what the closure hands you.
Recap
You can now read available space with GeometryReader, size views proportionally, and read frames for scroll-aware effects. 🎉
よくある質問
「GeometryReaderの基本」レッスンは無料ですか?
はい。「GeometryReaderの基本」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、SwiftUI Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 SwiftUI Academyコースには全4レッスンが含まれています。
「GeometryReaderの基本」で何を学びますか?
利用可能なスペースを測定してコンテンツのサイズを決めます。 ブラウザで直接実行するハンズオンコードでSwiftUI Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
SwiftUI Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSwiftUI Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「GeometryReaderの基本」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSwiftUI Academyレッスンでコードを書いて実行できますか?
はい。すべてのSwiftUI Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- GeometryReaderの基本
- カスタムアライメントガイド
- Layoutプロトコル
- フローレイアウトを作る