以下代码在 iOS 16.0 的 Xcode-14.0.0-Beta 5 上运行时打破了布局约束
struct ContentView: View {
@State var date = Date()
var body: some View {
DatePicker(selection: $date, displayedComponents: .date, label: { EmptyView() })
.datePickerStyle(.graphical)
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议如何修复或隐藏警告吗?
控制台警告:
2022-08-24 17:16:40.471325+0300 DatePickerProblem[77364:483284] [LayoutConstraints] 无法同时满足约束。可能至少以下列表中的约束之一是您不想要的。尝试这样做:(1)查看每个约束并尝试找出您不期望的约束;(2) 找到添加了不需要的约束的代码并修复它。(注意:如果您看到不理解的 NSAutoresizingMaskLayoutConstraints,请参阅 UIView 属性的文档translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x600003559180 h=--& v=--& _UIDatePickerCalendarTimeView:0x7fe15c322520.height == 0 (活动)>", "<NSLayoutConstraint:0x60000352bca0 _UIDatePickerCompactTimeLabel:0x7fe15c322bc0.centerY == _UIDatePickerCalendarTimeView:0x7fe15c322520.centerY - 1 (活动)>", "<NSLayoutConstraint:0x60000352bcf0 V:|-(> =0)-[_UIDatePickerCompactTimeLabel:0x7fe15c322bc0 ] (active, names: '|':_UIDatePickerCalendarTimeView:0x7fe15c322520 )>" ) 将尝试通过破坏约束来恢复 <NSLayoutConstraint:0x60000352bca0 _UIDatePickerCompactTimeLabel:0x7fe15c322bc0.centerY == _UIDatePickerCalendarTimeView:0x7fe15c322 520.centerY - 1(活动)> 制作符号断点在 UIViewAlertForUnsatisfiableConstraints 中在调试器中捕获此内容。<UIKitCore/UIView.h> 中列出的 UIView …
有没有办法格式化日期?(从图片中箭头指示的位置)我知道它是根据语言环境格式化的,但有没有办法自己格式化它?
struct ContentView: View {
@State private var selectedDate = Date()
var body: some View {
Form {
DatePicker(selection: $selectedDate, in: ...Date(), displayedComponents: .date) {
Text("From*")
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 当 TabView 中包含 UINavigationController 时,在 iOS 16 上设置 navigationTitle 不再有效。使用 iOS 14/15 运行代码,没有问题。如果 Tabview 被注释,iOS 16 也会出现导航标题。看来问题是由 TabView 引起的。我知道我可以将标题作为参数发送,但我也不想这样做,目前,切换到 NavigationVies 也不是一个选择。
import SwiftUI
@main
struct CustomUIKitNavigationApp: App {
var body: some Scene {
WindowGroup {
TabView {
NavigationViewControllerRepresentable {
VStack {
Text("why navigation title is not working anymore on iOS 16 when in TabView?")
.navigationTitle("navigation is not appearing")
}
}
}
}
}
}
struct NavigationViewControllerRepresentable<Content: View>: UIViewControllerRepresentable {
let nav = UINavigationController()
init(@ViewBuilder content: @escaping () -> Content) { …Run Code Online (Sandbox Code Playgroud)