简体   繁体   English

SwiftUI NavigationBar 标题下空白

[英]SwiftUI NavigationBar empty space under the title

I was working on Xcode 12 and upgraded to 13. Now I'm seeing a weird empty space under the navigation bar title text.我正在研究 Xcode 12 并升级到 13。现在我在导航栏标题文本下看到一个奇怪的空白区域。 I have shared some screenshots.我分享了一些截图。

空的空间

Here is the another image that have the scrollview, and the navigation bar is overlapping it.这是另一个具有滚动视图的图像,导航栏与它重叠。

Here is the code.这是代码。

struct ProductDetailScreen: View {
        
    let product: Product
    
    @State var productVariation: ProductVariation?
    
    var body: some View {
        ZStack{
            Color.themeBackground
                .ignoresSafeArea()
            VStack{
                VStack{
                    AsyncImage(
                        url: URL(string: product.image)!,
                        placeholder: {
                            ProgressView()
                                .progressViewStyle(CircularProgressViewStyle(tint: Color.themeBackground))
                        },
                        image: {
                            Image(uiImage: $0)
                                .resizable()
                        }
                    )
                    .frame(height: 250, alignment: .center)
                    .cornerRadius(10)
                    FixedSpacer(height: 10)
                    LazyVGrid(columns: [GridItem(.adaptive(minimum: 60))]){
                        ForEach(product.variations, id: \.self) { variation in
                            VariationSizeButtonView(productVariation: $productVariation, variation: variation)
                        }
                    }
                    
                    Spacer()
                    
                    if productVariation != nil {
                        NavigationButton(text: "Select Photos", destination: AnyView(SelectPhotosScreen(product: product, productVariation: self.productVariation!)))
                    }
                    
                }
                .frame(
                    minWidth: 0,
                    maxWidth: .infinity,
                    minHeight: 0,
                    maxHeight: .infinity,
                    alignment: .topLeading
                )
                Spacer()
            }
            .padding(.horizontal, 24)
        }
        .navigationBarTitle(product.name)
        .navigationBarTitleDisplayMode(.inline)
    }
}

重叠滚动视图

Here is the code for select photo screen.这是select照片屏幕的代码。

struct SelectPhotosScreen: View {
    
    @State private var id = 1
    @State var product: Product
    @State var uploadingPhotos = false
    @State var productVariation: ProductVariation
    @StateObject var selectedImagesViewModel = SelectedImagesViewModel()
    @EnvironmentObject var cartViewModel: CartViewModel
    
    let imageUploaderService = ImageUploaderService()
    
    
    var body: some View {
        ZStack{
            Color.themeBackground
                .ignoresSafeArea()
            VStack{
                VStack {
                    PhotoSelectionOptions(selectedImagesViewModel: selectedImagesViewModel)
                    SelectedPhotoDisplayer(selectedImagesViewModel: selectedImagesViewModel)
                }
                Spacer()
                if uploadingPhotos && (selectedImagesViewModel.pendingImages() > 0) {
                    ProgressView("Uploading....", value:  Float(selectedImagesViewModel.uploadedImages()), total: Float(selectedImagesViewModel.images.count))
                        .padding(.horizontal, 24)
                        .foregroundColor(.white)
                        .frame(maxWidth: .infinity)
                }
                if !selectedImagesViewModel.images.isEmpty && !uploadingPhotos{
                    RoundedButton(text: "Upload Photos", action: {
                        uploadingPhotos = true
                        imageUploaderService.uploadImages(selectedImagesViewModel: selectedImagesViewModel)
                    })
                }
                if (selectedImagesViewModel.pendingImages() <= 0) && (selectedImagesViewModel.uploadedImages() >= 1) {
                    NavigationButton(text: "Order Summary", destination: AnyView(OrderSummaryScreen(
                                                                                    cartItem: CartItem(
                                                                                        id: self.product.id,
                                                                                        selectedImages: self.selectedImagesViewModel,
                                                                                        product: self.product,
                                                                                        productVariation: self.productVariation
                                                                                    )
                                                                                )))
                }
            }
            .padding(.horizontal, 24)
        }
        .navigationBarTitle("Select Photos", displayMode: .inline)
    }
}

Both Screens are navigating from the home screen that's code is here.两个屏幕都从主屏幕导航,代码在这里。

struct ContentView: View {
    let greet = Greeting().greeting()

    var body: some View {
        NavigationView{
            HomeScreen()
                .navigationTitle("")
                .navigationBarHidden(true)
        }
        .navigationAppearance(backgroundColor: .themeBackground, foregroundColor: .white)
    }
}

It only happened after upgrading Xcode to 13 and iOS 15.它仅在将 Xcode 升级到 13 和 iOS 15 后发生。

Just set .navigationBarTitle("", displayMode:.inline)只需设置.navigationBarTitle("", displayMode:.inline)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM