๐ฐview hierarchy
SwiftUI โฉ view โฉ hierarchy
view hierarchy (่ฆๅๅฑค็ด)
root view ่ๅ ถๆๅซ็ๆๆๅญ่ฆๅ (descendants) ๅฝขๆ view hierarchyใ
view hierarchy
root view๏ผ่ฆๅๅฑค็ด็ๆไธๅฑค
parent view๏ผ่ฆๅๅฑค็ด็ไธๅฑค
child view๏ผ่ฆๅๅฑค็ด็ไธๅฑค
ๅจ container view ็็ๆณ๏ผๅคงๆฌ่่ฃก้ข็ views ๅฐฑๆฏ child viewsใ
// case: container view
HStack { // parent
Text("Hello") // child
Color.red // child
}ๅจๆ view modifiers ็ๆ ๆณไธ๏ผ่ฆๅ้ไพ็๏ผๅ้ข็ๆฏ child view๏ผๅพ้ข็ๆฏ parent viewใ
// case: view modifiers
view // child
.padding() // parent
.frame(width: 100, height: 100) // grand parent
.border(.black) // grand grand parentๅฆๆ็ตๅ่ตทไพ็๏ผ
// container view + view modifiers
HStack { // parent
Text("Hello") // child
Color.red // child
}
.padding() // parent
.frame(width: 100, height: 100) // grand parent
.border(.black) // grand grand parent้ๆ็ view hierarchy ๅฐฑๆ่ฎๆ๏ผ
Use a WindowGroup as a container for a view hierarchy that your app presents.
ๅจ view hierarchy ไธญ๏ผไธๅ view ๅ้ข็ view๏ผ็จฑ็บๅๆฏ (foreground)ใ
view size๏ผparent view proposes a size to the child views it contains, and the child views respond with a computed size.
Last updated
Was this helpful?