swiftUI transitions: Scale from some frame - like iOS Homescreen is doing when opening an App

后端 未结 2 560
鱼传尺愫
鱼传尺愫 2020-12-09 07:25

How do I get the effect in a translation, that iOS home screen does when opening an App: It scales the App to fullscreen, starting from the App-icon on the home screen?

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 07:31

    The above sample code should give you an idea on scaling an image

    
    struct ImageCustomScaling: View {
        // image to be scaled
        var scaleImage: Image
    
        // scale ratio
        var scaleTo: Double
    
        @State private var start = false
    
        var body: some View {
    
            VStack {
    
                scaleImage
                    .font(.title)
                    .scaleEffect(self.start ? CGFloat(scaleTo) : 1)
                    .opacity(self.start ? 1 : 0)
                    .animation(Animation.interpolatingSpring(stiffness: 25, damping: 5, initialVelocity: 10).delay(0.9))
    
            }
            .foregroundColor(.blue)
            .onAppear {
                self.start = true
            }
        }
    
    }
    
    

    Above can be called by something like below

    ImageCustomScaling(scaleImage: Image(systemName: "cloud.fill"), scaleTo: 5 )
    

    Added animation modifier to give visual cue. You can change it to meet your needs.

提交回复
热议问题