0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SwiftUIやってて出てきたGeometryReaderって

Posted at

はじめに

SwiftUIでサイドメニューを実装しようと

[https://swiswiswift.com/2020-02-20/:title]

こちらのサイトをみていたら
GeometryReader
という記述がありました。

SwiftUIのおそらくグラフとかアニメーションのTutorialで出てきたと思うのですが、自分は最初はそこは必要ないと思い飛ばしていました。

なので今回は自分が調べた内容を備忘録としてまとめます。

公式の定義

GeometryReaderの説明は独自のサイズと座標空間の関数としてコンテンツを定義するコンテナービュー。

親レイアウトに柔軟な優先サイズを返します。

とあります。


親のViewのサイズや座標空間を取得して子のViewで使えるって感じですかね。

サイドメニューの参考サイトの場合は画面のサイズを取得するため
body下で利用したのでBodyのサイズ、つまり画面サイズが取得できたと。

画面サイズの取得の仕方としては

UIScreen.main.boundsでも取得はできそうです。

逆に親Viewを指定というか選ぶ場合は

.background(指定したい親View)をすればいけるみたい。

他にも参考サイト先で面白い内容があるのでもう少し勉強しようと思います。

参考サイト

[https://qiita.com/masa7351/items/0567969f93cc88d714ac:title]

Apple公式Doc

[https://blog.personal-factory.com/2019/12/08/how-to-know-coorginate-space-by-geometryreader/:title]

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?