相关疑难解决方法(0)

在Xcode的调试控制台输出中禁用自动布局约束错误消息

有没有办法(暂时)禁用自动布局错误/警告消息:

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x170098420 H:[UIView:0x15c62c100(2)]>",
    "<NSLayoutConstraint:0x170098600 UIView:0x15c6294f0.leading == UIView:0x15c628d40.leadingMargin - 8>",
    "<NSLayoutConstraint:0x170098650 …
Run Code Online (Sandbox Code Playgroud)

xcode ios autolayout

63
推荐指数
4
解决办法
2万
查看次数

.navigationTitle aways 创建自动布局约束冲突

环境: Xcode Version 12.3 (12C33)
Version 12.3 (12C33)

我注意到NavigationTitle在更新到 Xcode 12.3 RC 后会破坏自动布局。
这是一个简单的示例(根据注释修改为现代语法):

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            VStack(alignment: .center, spacing: 10) {
                Text("Hello, world!")
                    .padding()
            }.navigationTitle(Text("Greetings World!"))
            .navigationBarTitleDisplayMode(.inline)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我在运行时得到的:

2020-12-09 11:42:19.994389-0800 UICheck[26092:799713] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you …
Run Code Online (Sandbox Code Playgroud)

uinavigationbar swiftui swiftui-14.3-defect

11
推荐指数
1
解决办法
772
查看次数

如何解决 SwiftUI 视图约束冲突?

我正在玩弄 SwiftUI 中的图像显示,并决定附加警报以在找不到图像时激活。

以下是缩略代码:

struct ContentView: View {
    ...
    @State var image: URLImage = URLImage()
    ...
    @State var showActionSheet = true

    var body: some View {
        ZStack {
            Color.green
            NavigationView {
                VStack {
                    Button(action: {
                        self.url = "https://xxxx.org/\(Int.random(in: 0 ..< 10)).png"
                        self.image.imageLoader.load(url: URL(string: self.url)!)
                    }) {
                        Text("Get Random Image")
                    }
                    image.actionSheet(isPresented: $showActionSheet) {
                        ActionSheet(title: Text("Action Time"), message: Text("Greetings Ric!"), buttons:
                            [.default(Text("First Button"), action: {
                                print("First Button")
                        })])
                    }
                }.navigationBarTitle(Text("Ric's Images"))
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我将“showAlertSheet”标志设置为“true”时,我会收到警报,但也会收到编译器的约束投诉:

2019-11-25 12:41:21.628064-0800 GetImages[32413:1078621] …

ios nslayoutconstraint swiftui

6
推荐指数
0
解决办法
1455
查看次数

swiftui - 如何避免“无法同时满足约束”错误?

我正在尝试将此问题的已接受答案中的代码应用于如何使 SwiftUI TextField 成为第一响应者。这是从该答案复制的代码,我尝试在 xcode 中使用它:

struct CustomTextField: UIViewRepresentable {

    class Coordinator: NSObject, UITextFieldDelegate {

        @Binding var text: String
        var didBecomeFirstResponder = false

        init(text: Binding<String>) {
            _text = text
        }

        func textFieldDidChangeSelection(_ textField: UITextField) {
            text = textField.text ?? ""
        }

    }

    @Binding var text: String
    var isFirstResponder: Bool = false

    func makeUIView(context: UIViewRepresentableContext<CustomTextField>) -> UITextField {
        let textField = UITextField(frame: .zero)
        textField.delegate = context.coordinator
        return textField
    }

    func makeCoordinator() -> CustomTextField.Coordinator {
        return Coordinator(text: $text)
    }

    func …
Run Code Online (Sandbox Code Playgroud)

xcode uikit swift swiftui

6
推荐指数
1
解决办法
2144
查看次数

SwiftUI navigationBarTitle 导致控制台警告

我试图隐藏后退按钮名称,解决方案是这两行:

.navigationBarHidden(true)
.navigationBarTitle("")
Run Code Online (Sandbox Code Playgroud)

一切工作正常,除了这个长控制台警告,这使得调试非常困难,因为我需要滚动或过滤很多才能看到所需的输出。

这条线导致了它:.navigationBarTitle("")

任何想法如何解决这一问题?

警告:

    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600003823de0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x11fe70c30]-(6)-[_UIModernBarButton:0x11fe6f370' ']   (active)>",
    "<NSLayoutConstraint:0x600003823e30 'CB_Trailing_Trailing' _UIModernBarButton:0x11fe6f370' '.trailing <= _UIButtonBarButton:0x11fe6eda0.trailing   (active)>",
    "<NSLayoutConstraint:0x600003850aa0 'UINav_static_button_horiz_position' _UIModernBarButton:0x11fe70c30.leading == UILayoutGuide:0x600002251500'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x600003850af0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x11fe6eda0]-(0)-[UILayoutGuide:0x600002251420'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x60000383b7a0 'UINavItemContentGuide-trailing' UILayoutGuide:0x600002251420'UINavigationBarItemContentLayoutGuide'.trailing …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift swift5 swiftui

5
推荐指数
0
解决办法
773
查看次数

如何消除这些与使用 SwiftUI 相关的常见 Firebase 警告?

我在 SwiftUI/Combine 应用程序中使用 Firebase,并且注意到一些警告,我想对其进行故障排除。他们没有破坏事情,但我想解决它们。我使用带有最新 Swift 包依赖项的 Xcode 12.4 时收到这些警告:GoogleUtilities 7.2.2 和 Firebase 7.7.0。

这是控制台中出现的第一个警告:

[GoogleUtilities/AppDelegateSwizzler][I-SWZ001014] App Delegate does not conform to UIApplicationDelegate protocol.
Run Code Online (Sandbox Code Playgroud)

作为参考,这是我配置 Firebase 的方式:

import SwiftUI
import Firebase

@main
struct MyApp: App {
    
    @StateObject var authState = AuthState()
    
    init() {
        FirebaseApp.configure()
    }
    
    var body: some Scene {
        
        WindowGroup {
            RootView()
                .environmentObject(authState)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是第二个警告,在我使用修饰符设置导航栏标题后出现.navigationBarTitle

[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't …
Run Code Online (Sandbox Code Playgroud)

navigationbar ios firebase swiftui

4
推荐指数
1
解决办法
1011
查看次数