Код: Выделить всё
struct FormattedContainer: View {
let content: Content
init(@ViewBuilder content: () -> Content) {
self.content = content()
}
var body: some View {
content
.padding()
.background(Color.gray.opacity(0.2))
}
}
Код: Выделить всё
struct ContentView: View {
@Namespace var animation
@State var isFlipped: Bool = false
var body: some View {
VStack {
FormattedContainer {
HStack {
Rectangle()
if isFlipped {
Text("This is the active container")
.layoutPriority(1)
.matchedGeometryEffect(id: "id", in: animation)
}
}
}
Spacer(minLength: 40)
FormattedContainer {
HStack{
if !isFlipped {
Text("This is the active container")
.layoutPriority(1)
.matchedGeometryEffect(id: "id", in: animation)
}
Rectangle()
}
}
}
.contentShape(Rectangle())
.padding()
.onTapGesture {
withAnimation {
isFlipped.toggle()
}
}
}
}
Если я добавляю форму клипа в мой контейнер, чтобы дать ему округлые углы: p> p>
, если я добавляю форму клипа в мой контейнер, чтобы дать ему округлые углы:
.
Код: Выделить всё
struct FormattedContainer: View {
let content: Content
init(@ViewBuilder content: () -> Content) {
self.content = content()
}
var body: some View {
content
.padding()
.background(Color.gray.opacity(0.2))
.clipShape(RoundedRectangle(cornerRadius: 20))
Подробнее здесь: [url]https://stackoverflow.com/questions/79537711/swiftui-matchedgeometryeffect-and-clipshape-animation-bug[/url]