0

我有一个带有视图的标准应用程序,您可以通过捏合手势进行缩放。这是工作,但一开始我有一点延迟,它看起来像跳跃的缩放。有人知道使它工作更顺畅的解决方案吗?这里的代码示例:

VStack {
Image("image")
    .resizable()
    .scaledToFill()
    .frame(width: UIScreen.main.bounds.width, height: 200)
    .scaleEffect(scale)
    .gesture(MagnificationGesture()
        .updating($scale, body: { (value, scale, trans) in
            scale = value.magnitude
        })
)

}

4

1 回答 1

0

为了解决“跳跃缩放”,您只需要添加一个动画。

例如,可能是这样的:

Image("image")
            .resizable()
            .scaledToFill()
            .frame(width: UIScreen.main.bounds.width, height: 200)
            .scaleEffect(scale)
            .gesture(MagnificationGesture()
                        .updating($scale, body: { (value, scale, trans) in
                    scale = value.magnitude
                })
            )
            .animation(Animation.easeInOut(duration: 2.0), value: scale)// Animation to solve the "jumpy zoom"

在此处输入图像描述

于 2021-10-20T07:10:17.717 回答