![](/img/trans.png)
[英]Run on simulator while having SDK that don't show classes on simulator ( prevent me from running)
[英]Simulator and Phone don't show the same matchedGeometryEffect result
我有一个非常简单的例子,我想让一个正方形更大。 在模拟器中一切看起来都很好,但是当我在手机上运行它时,正方形变得透明。
内容视图
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@Namespace var animation
@State var isBig:Bool = false
var body: some View {
ZStack {
Color(.red)
if(!isBig){
RectangleViewSmoll(isBig:$isBig, animation: animation)
}
if(isBig){
RectangleViewBig(isBig:$isBig,animation: animation)
}
}
.ignoresSafeArea()
}
}
小矩形
struct RectangleViewSmoll: View {
@Binding var isBig:Bool
var animation:Namespace.ID
var body: some View {
Rectangle()
.matchedGeometryEffect(id: "rectangle", in: animation)
.frame(width: 50, height: 50)
.onTapGesture {
withAnimation(.easeIn(duration: 2)){
isBig.toggle()
}
}
}
}
大长方形
struct RectangleViewBig: View {
@Binding var isBig:Bool
var animation:Namespace.ID
var body: some View {
Rectangle()
.matchedGeometryEffect(id: "rectangle", in: animation)
.frame(width: 500, height: 500)
.onTapGesture {
withAnimation(.easeIn(duration: 2)){
isBig.toggle()
}
}
}
}
问题在于 animation 线,尝试这样可以解决您的问题:
Rectangle()
.matchedGeometryEffect(id: "rectangle", in: animation)
.frame(width: 500, height: 500)
.onTapGesture {
isBig.toggle()
}
.animation(.easeIn(duration: 2))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.