为什么图片在SwiftUI中从视图顶部移动到屏幕中间?

时间:2020-06-08 20:29:14

标签: swift image swiftui

我对Image有疑问。打开视图时,Image位于屏幕顶部,被“卡住”到NavigationBar上。问题是,当我从图库中选择任何照片时,将显示所选照片。但是,从顶部看,它并不像刚开始时那样,而现在却处于完全不同的位置,即几乎在中间。

import SwiftUI

struct ScanWithPhotoFromLibrary: View {

    @State var cupWidth: String = ""
    @State var cupHeight: String = ""
    @State var stemLength: String = ""
    @State var leafWidth: String = ""
    @State var leafLength: String = ""

    @State private var showSheet: Bool = false
    @State private var showImagePicker: Bool = false
    @State private var sourceType: UIImagePickerController.SourceType = .camera

    @State private var userImage: UIImage?
    @State private var flowerName: String = ""
    @EnvironmentObject var env: ImagePickerCoordinator

    var body: some View {

        NavigationView{
            VStack{
                Image(uiImage: userImage ?? UIImage(named: "flower_logo")!)
                    .resizable()
                    .aspectRatio(contentMode:.fit)
                    .edgesIgnoringSafeArea(.top)
                    .frame(width: 375, height: 375)

            }

            .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .top)

        }
        .navigationBarTitle(Text(flowerName).foregroundColor(.blue), displayMode: .inline)
        .navigationBarItems(trailing:
                HStack {
                    Button("Library") {
                        self.showImagePicker = true
                        self.sourceType = .photoLibrary
                        print("Library tapped!")
                       }
                   }
           )
           .sheet(isPresented: $showImagePicker) {
               ImagePicker(image: self.$userImage, isShown: self.$showImagePicker, flowerName: self.$flowerName, sourceType: self.sourceType)

           }
       }
}

struct ScanWithPhotoFromLibrary_Previews: PreviewProvider {
    static var previews: some View {
        ScanWithPhotoFromLibrary()
    }
}

上面是我的课堂,我在这里显示此图像。 显示器怎么了?

0 个答案:

没有答案