简体   繁体   English

模拟器和电话不显示相同的匹配几何效果结果

[英]Simulator and Phone don't show the same matchedGeometryEffect result

I have a very simple example where I want to make a square larger.我有一个非常简单的例子,我想让一个正方形更大。 In the simulator everything looks fine but when I run it on the phone the square becomes transparent.在模拟器中一切看起来都很好,但是当我在手机上运行它时,正方形变得透明。

On simulator在模拟器上

On phone在电话上

Content View内容视图

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()
    }
}

Small Rectangle小矩形

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()
                }
            }
    }
}

Big rectangle大长方形

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()
                }
            }
    }
}

The problem is with the animation line, try like this will fix your problem:问题在于 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM