I’m creating an iOS app utilizing SwiftUI and have encountered an Auto Format constraint battle situation that seems when tapping on a TextField inside a LoginView. I’ve tried a number of troubleshooting steps however have not been capable of resolve it.
Error Message:
In all probability a minimum of one of many constraints within the following checklist is one you don't need.
Do that:
(1) have a look at every constraint and check out to determine which you do not anticipate;
(2) discover the code that added the undesirable constraint or constraints and repair it.
(
"<NSLayoutConstraint:0x6000021298b0 'accessoryView.backside' _UIRemoteKeyboardPlaceholderView:0x10460dd10.backside == _UIKBCompatInputView:0x1059220e0.high (lively)>",
"<NSLayoutConstraint:0x60000217a620 'assistantHeight' SystemInputAssistantView.peak == 45 (lively, names: SystemInputAssistantView:0x10591ce60 )>",
"<NSLayoutConstraint:0x60000217d090 'assistantView.backside' SystemInputAssistantView.backside == _UIKBCompatInputView:0x1059220e0.high (lively, names: SystemInputAssistantView:0x10591ce60 )>",
"<NSLayoutConstraint:0x60000217d040 'assistantView.high' V:[_UIRemoteKeyboardPlaceholderView:0x10460dd10]-(0)-[SystemInputAssistantView] (lively, names: SystemInputAssistantView:0x10591ce60 )>"
)
Will try to get well by breaking constraint
<NSLayoutConstraint:0x60000217d040 'assistantView.high' V:[_UIRemoteKeyboardPlaceholderView:0x10460dd10]-(0)-[SystemInputAssistantView] (lively, names: SystemInputAssistantView:0x10591ce60 )>
This error seems within the console after I click on on the TextField in my LoginView whereas operating the code on a simulation. The app does not crash, however the console signifies there’s a constraint battle associated to the keyboard. Here is my LoginView:
struct LoginView: View {
@StateObject var viewModel = LoginViewModel()
var physique: some View {
NavigationStack {
VStack {
Spacer()
Picture("brand")
.resizable()
.scaledToFit()
.body(width: 150, peak: 100)
VStack {
TextField("Enter your e mail", textual content: $viewModel.e mail)
.autocapitalization(/*@START_MENU_TOKEN@*/.none/*@END_MENU_TOKEN@*/)
.modifier(TextFieldModifier())
SecureField("Enter your password", textual content: $viewModel.password)
.modifier(TextFieldModifier())
}
Button {
print("Present forgot password")
} label: {
Textual content("Forgot Password")
.font(.footnote)
.fontWeight(.semibold)
.padding(.high)
.padding(.trailing, 20)
}
.body(maxWidth: .infinity, alignment: .trailing)
Button {
Activity { attempt await viewModel.signIn() }
} label: {
Textual content("Login")
.font(.subheadline)
.fontWeight(.semibold)
.foregroundColor(.white)
.body(width: 360, peak: 44)
.background(Coloration(.black))
.cornerRadius(8)
}
.padding(.vertical)
HStack {
Rectangle()
.body(width: (UIScreen.most important.bounds.width / 2) - 40, peak: 0.5)
Textual content("OR")
.font(.footnote)
.fontWeight(.semibold)
.foregroundColor(.grey)
Rectangle()
.body(width: (UIScreen.most important.bounds.width / 2) - 40, peak: 0.5)
}
.foregroundColor(.grey)
HStack {
Picture("facebook_logo")
.resizable()
.body(width: 20, peak: 20)
Textual content("Proceed with Fb")
.font(.footnote)
.fontWeight(.semibold)
.foregroundColor(Coloration(.systemBlue))
}
.padding(.high, 8)
Spacer()
Divider()
NavigationLink {
AddEmailView()
.navigationBarBackButtonHidden(true)
} label: {
HStack (spacing: 3) {
Textual content("Haven't got an account?")
Textual content("Signal Up")
.fontWeight(.semibold)
}
.font(.footnote)
}
.padding(.vertical, 16)
}
}
}
}
#Preview {
LoginView()
}
And my TextFieldModifier:
struct TextFieldModifier: ViewModifier {
func physique(content material: Content material) ->some View {
content material
.font(.subheadline)
.padding(12)
.background(Coloration(.systemGray6))
.cornerRadius(10)
.padding(.horizontal, 24)
.padding(.high)
}
}
Questions:
- What might be inflicting this Auto Format constraint battle in a SwiftUI app?
- Are there any recognized points with SwiftUI’s TextField and keyboard interactions that may result in such constraints points?
- Any strategies on how you can debug or resolve this constraint battle?
Makes an attempt to Resolve:
- I’ve checked the TextFieldModifier for any potential points but it surely appears commonplace.
- I’ve tried simplifying the view by eradicating different components, however the situation persists.
- The problem appears to happen whatever the simulator machine or iOS model I take advantage of.