ZacharyKhan / ZKCarousel

A simple carousel implementation written in Swift
MIT License
289 stars 57 forks source link

Conflicting Constraint Errors #20

Closed MMooreGitHub closed 6 years ago

MMooreGitHub commented 6 years ago

Hi,

I'm receiving the following message below when running the example app you provided. Both natively as well as ingested within my app. Also, it's important to note I updated my POD to the latest today and am running ZKCarousel (0.1.5) & (0.1.9) I setup a symbolic breakpoint and discovered that the offending code is: ZKCarousel.swift extension UIView {

func addConstraintsWithFormat(_ format: String, views: UIView...) {

var viewsDictionary = [String: UIView]()
for (index, view) in views.enumerated() {
    let key = "v\(index)"
    viewsDictionary[key] = view
    view.translatesAutoresizingMaskIntoConstraints = false
}

**addConstraints(**NSLayoutConstraint.constraints(withVisualFormat: format, options: NSLayoutFormatOptions(), metrics: nil, views: viewsDictionary))

} }

Also: setup(){ self.addConstraintsWithFormat("V:[v0(43)]-[v1]", views: self.titleLabel, self.descriptionLabel) }

I've tested against an iPhone Xs Max and iPhone 6s plus Error Below: 2018-10-04 14:44:23.392251-0400 ZKCarousel_Example[459:44964] [LayoutConstraints] 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. ( "<NSLayoutConstraint:0x2827c0a50 UILabel:0x105110440.bottom == UILabel:0x105118060.top + 8 (active)>", "<NSLayoutConstraint:0x2827c12c0 V:[UILabel:0x105110440]-(NSSpace(8))-[UILabel:0x105118060] (active)>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x2827c12c0 V:[UILabel:0x105110440]-(NSSpace(8))-[UILabel:0x105118060] (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 2018-10-04 14:44:24.892541-0400 ZKCarousel_Example[459:44964] [LayoutConstraints] 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. ( "<NSLayoutConstraint:0x2827d3520 UILabel:0x105215de0.bottom == UILabel:0x1052160d0.top + 8 (active)>", "<NSLayoutConstraint:0x2827d3c00 V:[UILabel:0x105215de0]-(NSSpace(8))-[UILabel:0x1052160d0] (active)>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x2827d3c00 V:[UILabel:0x105215de0]-(NSSpace(8))-[UILabel:0x1052160d0] (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 2018-10-04 14:44:25.076927-0400 ZKCarousel_Example[459:44964] [LayoutConstraints] 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. ( "<NSLayoutConstraint:0x2827c1680 UILabel:0x10510ddd0.bottom == UILabel:0x105104fa0.top + 8 (active)>", "<NSLayoutConstraint:0x2827d32a0

MMooreGitHub commented 6 years ago

Note: This was originally reported under: https://github.com/ZacharyKhan/ZKCarousel/issues/18

ZacharyKhan commented 6 years ago

Interesting, I'm not receiving any of these errors. I will look into it again and try to replicate your errors. It has to do with auto layout constraints. The function trying to assign constraints from a visual constraint format is having issues. I can remove this function and simply apply the constraints programmatically, which may fix the issue.

Also, it's important to note I updated my POD to the latest today and am running ZKCarousel (0.1.5) & (0.1.9)

Which version are you running when you experience the error, 0.1.5 or 0.1.9?

ZacharyKhan commented 6 years ago

I've pushed 0.2.0 to cocoa pods.

run pod update and make sure you are running only the latest version, which is 0.2.0 as of right now. Any version prior to this may have errors or issues due to the latest updates with the Swift language and Xcode.

I am able to download the example project, run pod update to ensure I am on 0.2.0 and build/run successfully without any errors in the log.

Let me know if this fixes any of your errors.

MMooreGitHub commented 6 years ago

Hi Zachary, Thanks for the update. I updated your example project as well as my workspace pod file to use version 0.2.0 and am still receiving the same error regarding constraints.

Please find console output below: 2018-10-10 15:08:30.318034-0400 ZKCarousel_Example[1609:240818] [LayoutConstraints] 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. ( "<NSLayoutConstraint:0x282501b30 UILabel:0x153d109d0.bottom == UILabel:0x153d14120.top + 8 (active)>", "<NSLayoutConstraint:0x282501d60 V:[UILabel:0x153d109d0]-(NSSpace(8))-[UILabel:0x153d14120] (active)>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x282501d60 V:[UILabel:0x153d109d0]-(NSSpace(8))-[UILabel:0x153d14120] (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 2018-10-10 15:08:31.804119-0400 ZKCarousel_Example[1609:240818] [LayoutConstraints] 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. ( "<NSLayoutConstraint:0x282537480 UILabel:0x155c0a660.bottom == UILabel:0x155c0a950.top + 8 (active)>", "<NSLayoutConstraint:0x2825376b0 V:[UILabel:0x155c0a660]-(NSSpace(8))-[UILabel:0x155c0a950] (active)>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x2825376b0 V:[UILabel:0x155c0a660]-(NSSpace(8))-[UILabel:0x155c0a950] (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 2018-10-10 15:08:31.972985-0400 ZKCarousel_Example[1609:240818] [LayoutConstraints] 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. ( "<NSLayoutConstraint:0x282503660 UILabel:0x153d23170.bottom == UILabel:0x153d24470.top + 8 (active)>", "<NSLayoutConstraint:0x282503890 V:[UILabel:0x153d23170]-(NSSpace(8))-[UILabel:0x153d24470] (active)>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x282503890 V:[UILabel:0x153d23170]-(NSSpace(8))-[UILabel:0x153d24470] (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 2018-10-10 15:08:48.498446-0400 ZKCarousel_Example[1609:240818] [LayoutConstraints] 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. ( "<NSLayoutConstraint:0x282537d40 UILabel:0x155a03f90.bottom == UILabel:0x155a04a90.top + 8 (active)>", "<NSLayoutConstraint:0x282537f70 V:[UILabel:0x155a03f90]-(NSSpace(8))-[UILabel:0x155a04a90] (active)>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x282537f70 V:[UILabel:0x155a03f90]-(NSSpace(8))-[UILabel:0x155a04a90] (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

ZacharyKhan commented 6 years ago

@MMooreGitHub I’m not sure how you are receiving these errors. I’ve completely removed the use of the constraints via visual format.

When I build & run 0.2.0 I do not receive any of those errors.

Can anyone confirm they also receive layout errors when building and running the latest 0.2.0?

Sent with GitHawk

MMooreGitHub commented 6 years ago

Hi Zachary,

  1. What version of Xcode are you running? I'm running 10.0
  2. Have you tried holding another machine?
ZacharyKhan commented 6 years ago

Hi Zachary,

  1. What version of Xcode are you running? I'm running 10.0
  2. Have you tried holding another machine?

I am using Xcode 10.0.0, I have not tried to run it on another machine as I only have access to one Mac OS X computer. If it helps, I am also running the latest Mac OS X Mojave 10.14.

MMooreGitHub commented 6 years ago

Hi Zachary,

I've performed some additional tests and have some preliminary conclusions to share"

i. I ran ZK Example project both locally and on our VM and am no longer able to reproduce. Note the example uses swift 4 ii.I ran my project which uses the Carousel and am still able to reproduce. Note, my project uses swift 4.2 iii. Conclusion: It’s probably attributed to my code. Given that, we can close the ticket and I will research further using symbolic breakpoints

ZacharyKhan commented 6 years ago

Okay, sounds good. Let me know if there’s anything I can do.

If your project is open-source, I’m happy to take a look and submit a PR to your repo.

The issue has to do with the way you are laying out the subviews. Two or more objects have multiple constraints that are conflicting with each other (i.e. two constraints pulling away with equal priority, etc). Look at how you are adding the ZKCarousel to your view.

@MMooreGitHub

ZacharyKhan commented 6 years ago

Also, try one thing for me. Update to the latest 0.2.0 pod and go into the ZKCarousel.swift file. You will see an extension for UIView that contains the offending function, which adds constraints via a visual format.

Remove this entire function and run your project. Let me know if this does anything. If so, I can make some more changes on my end.

Sent with GitHawk