Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SwiftUI-如何提高使用withAnimation移动的对象的帧速率?_Swiftui - Fatal编程技术网

SwiftUI-如何提高使用withAnimation移动的对象的帧速率?

SwiftUI-如何提高使用withAnimation移动的对象的帧速率?,swiftui,Swiftui,我可以通过改变图像的位置并使用withAnimation平滑过渡来移动图像。但是,动画的帧速率是不同的,这是不好的,因为我希望能够通过点击移动对象来与它交互。如何提高动画的帧速率(或平滑度)?如果不可能,在SwiftUI视图中移动对象的最佳方式是什么?我是Swift的新手,任何帮助都将不胜感激。谢谢 我的代码:(设备位于横向btw中) struct test_moving_tile: View { var moveTo: Double var speed: Double

我可以通过改变图像的位置并使用withAnimation平滑过渡来移动图像。但是,动画的帧速率是不同的,这是不好的,因为我希望能够通过点击移动对象来与它交互。如何提高动画的帧速率(或平滑度)?如果不可能,在SwiftUI视图中移动对象的最佳方式是什么?我是Swift的新手,任何帮助都将不胜感激。谢谢

我的代码:(设备位于横向btw中)

struct test_moving_tile: View {

    var moveTo: Double
    var speed: Double
    @State var location = CGPoint(x: Constants.screenWidth / 2, y: -50)

    var body: some View {
        LazyHStack{
            RegularTile(size: 100)
                .frame(width: Constants.screenWidth, height: Constants.screenHeight)
                .position(location)
                .onAppear{
                    moveTile()
                }
        }   
    }

    func moveTile(){
        withAnimation(Animation.linear(duration: speed)){
            location = CGPoint(x: moveTo, y: Double(Constants.screenHeight + 50))
        }
    }
}