为什么为地图视图框架设置动画如此缓慢

问题描述

我正在创建一个包含Map视图的iOS 14应用。可以将以下内容粘贴到ContentView.swift iOS模板中。如果运行代码并按增大或减小键,则矩形和地图视图的动画更改会非常慢。为什么?

我做错什么了吗?还是地图视图性能根本不够好?

任何提示,我可以更改哪些内容以使其更快?

import SwiftUI
import MapKit

struct ContentView: View {
    @State private var coord1 : CGFloat = 300.0
    @State private var coord2 : CGFloat = 310.0
    @State private var region = MKCoordinateRegion(
        center: CLLocationCoordinate2D(
            latitude: 52,longitude: 0
        ),span: MKCoordinateSpan(
            latitudeDelta: 5,longitudeDelta: 5
        )
    )
    private func increase() {
        coord1 = coord1 + 100
        coord2 = coord2 + 100
    }
    private func decrease() {
        coord1 = coord1 - 100
        coord2 = coord2 - 100
    }
    
    var body: some View {
        VStack {
            Spacer()
            ZStack {
                Rectangle()
                    .frame(width: coord2,height: coord2,alignment:.center)
                    .animation(.spring())
                Map(coordinateRegion: $region)
                    .frame(width: coord1,height: coord1,alignment:.center)
                    .animation(.spring())
           }
            Spacer()
            HStack {
                Spacer()
                Button(action: increase,label: {
                    Text("increase")
                }).frame(width:100,height:100,alignment:.center)
                Spacer()
                Button(action: decrease,label: {
                    Text("decrease")
                }).frame(width:100,alignment:.center)
            }.frame(width: 200,alignment:.center)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

如果你不在这里

Map(coordinateRegion: $region)
 .frame(width: coord1,alignment:.center)
 .animation(.spring())

动画按预期运行。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...