我对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()
}
}
上面是我的课堂,我在这里显示此图像。 显示器怎么了?