Last updated 4 months ago
Was this helpful?
SwiftUI โฉ view โฉ drawing โฉ .compositingGroup()
.compositingGroup()
shadow๏ผๅฆๆ่ฆๅนซๆดๅ container view ๅ ้ฐๅฝฑ๏ผ้็จๅฐ .compositingGroup()ใ
ๅจ even-odd fill mode ไฝฟ็จ็ไพๅญไธญ๏ผๅฆๆๆฒ็จ .compositingGroup()๏ผ้ฃๆ็ฉบ็้จๅ้ฝๆๆๅฝฑๅญใ
ๆๆ็ container view (HStack, VStack, ZStack ็ญ) ้ฝๆๅๅฑค็ๆๆ๏ผๅพไพ็ view ็ๅๅฑค้ฝๆฏ้ซๆผๅ้ข็ view๏ผๆไปฅๅฆๆๆๅฝฑๅญ็่ฉฑ๏ผๆ็ๅจๅ้ข็ view ่บซไธใไฝๅจ container view ่บซไธ็จ .compositingGroup() ๅฐฑๅฏไปฅๅฐๆๆๅๅฑคๅ็บใๅไธๅๅฑคใใ
import SwiftUI typealias HA = HorizontalAlignment typealias VA = VerticalAlignment let w: CGFloat = 100 let h: CGFloat = 50 let r1 = Rectangle().padding(1).frame(w, h).foregroundColor(.pink) let r2 = Rectangle().padding(1).frame(h, w).foregroundColor(.blue) struct MyRects: View { var body: some View { ZStack { r1 .alignmentGuide(HA.center) { $0[.leading] } .alignmentGuide(VA.center) { $0[.bottom] } r1 .alignmentGuide(HA.center) { $0[.trailing] } .alignmentGuide(VA.center) { $0[.top] } r2 .alignmentGuide(HA.center) { $0[.trailing] } .alignmentGuide(VA.center) { $0[.bottom] } r2 .alignmentGuide(HA.center) { $0[.leading] } .alignmentGuide(VA.center) { $0[.top] } }// VStack (container) .aspectRatio(1, contentMode: .fit) } } // live view struct ContentView: View { var body: some View { HStack { MyRects() // โญ๏ธ ไธๅๅๅฑค๏ผๅฝฑๅญๆๆๅฑคๆฌกๆ MyRects() .compositingGroup() // โญ๏ธ ่ฎ็บๅไธๅๅฑค }// HStack .padding() .shadow(color: .black, radius: 4, x: 4, y: 4) .background(Color.gray) } }
SwiftUI โฉ View โฉ .compositingGroup()
ChaoCode โฉ ๅจ SwiftUI ไธญๆฟ View ๅ ไธ้ฐๅฝฑ
Let the Shapes be on the same layer - SO