Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.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
Swift GeometryReader似乎在更改使用其大小数据的视图布局。我怎样才能避免这种情况?_Swift_Layout_Swiftui_Geometryreader - Fatal编程技术网

Swift GeometryReader似乎在更改使用其大小数据的视图布局。我怎样才能避免这种情况?

Swift GeometryReader似乎在更改使用其大小数据的视图布局。我怎样才能避免这种情况?,swift,layout,swiftui,geometryreader,Swift,Layout,Swiftui,Geometryreader,我希望我的图标图像是总屏幕可用性宽度的1/3。我的代码如下: var body: some View { GeometryReader { geometry in Image(systemName: "square.dashed").resizable() .aspectRatio(contentMode: .fit).frame(maxWidth: geometry.size.width/3)

我希望我的图标图像是总屏幕可用性宽度的1/3。我的代码如下:

    var body: some View {
        GeometryReader { geometry in
            Image(systemName: "square.dashed").resizable()
                .aspectRatio(contentMode: .fit).frame(maxWidth: geometry.size.width/3)
        }
    }
当我这样做时,图标会显示在屏幕的左上角,它不会像我想象的那样保持在中间。例如,这可以正常工作,但不是基于屏幕大小的动态

    var body: some View {
        Image(systemName: "square.dashed").resizable()
            .aspectRatio(contentMode: .fit).frame(maxWidth: 200)
    }

以下是可能的解决方案(使用Xcode 12.1/iOS 14.1测试)


万岁,真管用。非常感谢。对我来说,GeometryReader并不是布局数字,这似乎很奇怪。
    GeometryReader { geometry in
        Image(systemName: "square.dashed").resizable()
            .aspectRatio(contentMode: .fit).frame(maxWidth: geometry.size.width/3)
            .frame(maxWidth: .infinity, maxHeight: .infinity)
    }