Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

「ZStack より .overlay と .background を好め」の追加 #43

Open
uhooi opened this issue Jun 30, 2022 · 3 comments
Open

「ZStack より .overlay と .background を好め」の追加 #43

uhooi opened this issue Jun 30, 2022 · 3 comments

Comments

@uhooi
Copy link

uhooi commented Jun 30, 2022

トビさんと Twitter でお話しした際に出た Effective な項目です。

可読性もそうですが、複数の View について異なるAlignment を貼りたい場合など、ZStack ではかなり面倒になったりします。(たぶん一度遭遇すれば納得できるかと思います

ZStack を使いたいとなるのは、 zIndex を使いたいケースや、ベースとなる View の frame に縛られないようにしたいケースだけだと、現時点では考えていますー

References

@uhooi
Copy link
Author

uhooi commented Jul 4, 2022

.overlay を3つくらい重ねたいケースが出てきたのですが、それは ZStack を使ったほうがいいのでしょうか…?
もしくは1つの .overlay で実現できる…?

@YusukeHosonuma
Copy link
Owner

.overlay.backgroundもいくらでも重ねがけできるので、基本的にはZStackは使わなくても大丈夫かと思います(たぶん...
https://www.swiftbysundell.com/articles/backgrounds-and-overlays-in-swiftui/

どういう UI なのかによりますが、もしかしたら ZStack で面倒なケースに当たるのでは、と思います。(よろしければぜひ試されてください 🙏

複数の View について異なるAlignment を貼りたい場合など、ZStack ではかなり面倒になったりします。

@uhooi
Copy link
Author

uhooi commented Jul 4, 2022

おお…まさに自分の知りたいことが書いてありました😭
.overlay はいくら重ねがけしても問題なさそうですね、ありがとうございますー!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants