Swift default AlertViewController breaking constraints
This error is not critical, seems to be unfixed bug form Apple. This constraint appears in animation style just after presenting. I tried to catch and change it (change values, relations, priority) before presenting – no success because of this dynamically added constraints.
When you turn off animation in self.present(alert, animated: false)
and using alert.view.addSubview(UIView())
– the error disappears. I can't explain it, but it works!
let alert = UIAlertController(title: "Change your profile image", message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Photo Library", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Online Stock Library", style: .default, handler: nil))
let cancel = UIAlertAction(title: "Cancel", style: .destructive, handler: nil)
alert.addAction(cancel)
alert.view.addSubview(UIView()) // I can't explain it, but it works!
self.present(alert, animated: false)
Presenting UIAlertController (in actionsheet style) caused mysterious autolayout warning
This is a bug which is not fixed by Apple team this bug is related to alerts and action sheets related to animation. You may follow these links to verify this:-
UIAlertController's actionSheet gives constraint error on iOS 12.2 / 12.3
Swift default AlertViewController breaking constraints
The solution for this is to pass animation value as false like:-
controller.present(alertController, animated: false, completion: nil)
I have present the UIAlertController without animation and warning got vanished.
or you may try this solution mentioned in the one of the links of stackoverflow:-
@IBAction func buttonTapped(_ sender: UIButton) {
...
self.present(alertController,animated: true,completion: nil)
alertController.view.subviews.flatMap({$0.constraints}).filter{ (one: NSLayoutConstraint)-> (Bool) in
return (one.constant < 0) && (one.secondItem == nil) && (one.firstAttribute == .width)
}.first?.isActive = false
}
Swift - Unable to simultaneously satisfy constraints
All action sheets do that. It’s an Apple bug. It has no effect on your app’s functionality. Ignore it and move on.
How to fix ActionSheet of UIAlertController has the conflict constraint error in Swift
You may have to manually silent the constraint alert.
@IBAction func newToDoBarButtonTapped(_ sender: UIBarButtonItem) {
...
self.present(alertController,animated: true,completion: nil)
alertController.view.subviews.flatMap({$0.constraints}).filter{ (one: NSLayoutConstraint)-> (Bool) in
return (one.constant < 0) && (one.secondItem == nil) && (one.firstAttribute == .width)
}.first?.isActive = false
}
Related Topics
Calayer with Transparent Hole in It
Multiple Uilabels Inside a Self Sizing Uitableviewcell
Uilabel Wrong Word Wrap in iOS 11
iOS Nsdate() Returns Incorrect Time
How to Detect When Avplayer Video Ends Playing
How to Use Nsurlsessiondatatask in Swift
Run Timer in 'Background' When App Is Closed
How to Create P12 Certificate for iOS Distribution
How to Add Badges on Uibarbutton Item
How to Add Equal Spacing and Equal Width for Button in iOS Auto Layout
How to Style Uitextview to Like Rounded Rect Text Field
How to Open Mail App from Swift
How to Password Protect Writing to Nfc Ntag216 Tag on iOS 13 Using Nfc Core
Launch Apple Mail App from Within My Own App
Ios8 Photos Framework: How to Get the Name(Or Filename) of a Phasset
Trigger Local Notifications Automatically Daily on Dynamic Time Given in Arrays Objective C iOS