ios DatePicker高度在.fullScreenCover(_:)中显示时 Flink - SwiftUI

juud5qan  于 2023-06-25  发布在  iOS
关注(0)|答案(1)|浏览(89)

我正在尝试呈现一个带有DatePicker的视图。当视图突然呈现时,DatePicker高度会随着 Flink 而增加。
Working on min iOS version 14
这里是代码,

struct ContentView: View {
    
    @State private var showDatePicker : Bool = false
    @State private var pickedDate : Date = Date()
    
    var body: some View {
        VStack{
            Spacer()
            
            Button {
                showDatePicker.toggle()
            } label: {
                Text("Show Date Picker")
            }

            
            Spacer()
        }
        .fullScreenCover(isPresented: $showDatePicker) {
            DatePicker("Date Picker",
                       selection: $pickedDate,
                       displayedComponents: [.date])
            .datePickerStyle(.graphical)
            .padding(.horizontal)
        }
    }
}

当通常在视图中通过标志进行隐藏/显示时,它工作得很好。使用.fullScreenCover(_:)演示时出现 Flink

dy1byipe

dy1byipe1#

试试这一个正在工作。

**Xcode:14.3iOS目标:**16.2

@State private var showDatePicker : Bool = false
@State private var pickedDate = Date()
    
var body: some View {
    VStack{
        Spacer()
        Button {
            showDatePicker.toggle()
        } label: {
            Text("Show Date Picker")
        }
        Spacer()
    }
    .fullScreenCover(isPresented: $showDatePicker) {
        DatePicker("Date Picker",
                   selection: $pickedDate,
                   displayedComponents: [.date])
        .datePickerStyle(.graphical)
        .padding(.horizontal)
        .onAppear{
            self.pickedDate = Date()
        }
    }
}

相关问题