Programmatically Setting Constraints Causes Conflict in Swift - ios

As i posted in this GitHub issue, I am having trouble with some hidden constraints that throw an error whenever I try to add my own constraints
2016-04-18 19:22:04.270 Metric Time[1519:447809] 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)
(
"<NSAutoresizingMaskLayoutConstraint:0x15e670e70 h=--& v=--& Metric_Time.View:0x15e692e70.midX == + 115>",
"<NSLayoutConstraint:0x15e5048c0 Metric_Time.View:0x15e692e70.centerX == UIView:0x15e6953e0.centerX>",
"<NSAutoresizingMaskLayoutConstraint:0x15e55fd30 h=-&- v=-&- 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UIView:0x15e6953e0] (Names: '|':UIWindow:0x15e688ed0 )>",
"<NSLayoutConstraint:0x15e54e750 'UIView-Encapsulated-Layout-Width' H:[UIView:0x15e6953e0(320)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x15e5048c0 Metric_Time.View:0x15e692e70.centerX == UIView:0x15e6953e0.centerX>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.`
I have tried looking for the places that these constraints could have been created, but searching my ViewController.swift file for keywords such as constraint, layout .etc turned up only the code that I wrote.
My code is all on GitHub if anyone wants to mess around with it.

If you are going to add constraints programmatically, you need to turn off translateAutoresizingMaskIntoConstraints. You also don't have enough constraints to satisfy the layout engine. Remember that UIView's don't have an intrinsic size and if you are using auto layout with a view you need to set everything with constraints and not rely on a mixture of constraints and frames. one possible solution is to add some code like:
self.view.addSubview(clockView)
clockView.translatesAutoresizingMaskIntoConstraints = false
clockView.centerYAnchor.constraintEqualToAnchor(self.view.centerYAnchor, constant: 0.0).active = true
clockView.centerXAnchor.constraintEqualToAnchor(self.view.centerXAnchor, constant: 0.0).active = true
clockView.widthAnchor.constraintEqualToConstant(230.0).active = true
clockView.heightAnchor.constraintEqualToConstant(230.0).active = true
However this is not exactly what you want as when it is in landscape your clock overlays your label. But you could fix that by playing with clockView.centerYAnchor.constraintEqualToAnchor(self.view.centerYAnchor, constant: 0.0).active = true

Related

iOS 11: "Unable to simultaneously satisfy constraints"

always running into the FoodTracker tutorial; following this step: "Implement a custom control"
https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ImplementingACustomControl.html#//apple_ref/doc/uid/TP40015214-CH19-SW1
and when executing the first checkpoint the simulator shows a red rectangle instead of a square as indicated on the tutorial; on the debug pane I get:
2018-02-09 11:19:42.130595+0100 FoodTracker[7439:80369] [MC] Lazy loading NSBundle MobileCoreServices.framework
2018-02-09 11:19:42.131628+0100 FoodTracker[7439:80369] [MC] Loaded MobileCoreServices.framework
2018-02-09 11:19:42.165143+0100 FoodTracker[7439:80369] [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:0x60400028a3c0 UIButton:0x7f8a0bd0e330.width == 44 (active)>",
"<NSLayoutConstraint:0x60400028cda0 'UISV-canvas-connection' FoodTracker.RatingControl:0x7f8a0bd08890.leading == UIButton:0x7f8a0bd0e330.leading (active)>",
"<NSLayoutConstraint:0x60400028ce40 'UISV-canvas-connection' H:[UIButton:0x7f8a0bd0e330]-(0)-| (active, names: '|':FoodTracker.RatingControl:0x7f8a0bd08890 )>",
"<NSLayoutConstraint:0x60400028c940 'UIView-Encapsulated-Layout-Width' FoodTracker.RatingControl:0x7f8a0bd08890.width == 200 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400028a3c0 UIButton:0x7f8a0bd0e330.width == 44 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-02-09 11:19:42.165949+0100 FoodTracker[7439:80369] [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:0x60400028a370 UIButton:0x7f8a0bd0e330.height == 44 (active)>",
"<NSLayoutConstraint:0x60400028a320 'UISV-canvas-connection' FoodTracker.RatingControl:0x7f8a0bd08890.top == UIButton:0x7f8a0bd0e330.top (active)>",
"<NSLayoutConstraint:0x60400028cf30 'UISV-canvas-connection' V:[UIButton:0x7f8a0bd0e330]-(0)-| (active, names: '|':FoodTracker.RatingControl:0x7f8a0bd08890 )>",
"<NSLayoutConstraint:0x60400028c990 'UIView-Encapsulated-Layout-Height' FoodTracker.RatingControl:0x7f8a0bd08890.height == 110 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400028a370 UIButton:0x7f8a0bd0e330.height == 44 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
I think that something is changed when programmatically create the button and applying custom constraints here: (I'm working with Swift and Xcode 9)
// Add constraints
button.translatesAutoresizingMaskIntoConstraints = false
button.heightAnchor.constraint(equalToConstant: 44.0).isActive = true
button.widthAnchor.constraint(equalToConstant: 44.0).isActive = true
Any hint to solve the issue is welcome.
Please note that I'm building a custom control... All the notes I've found googling around seems not to be applicables.
Epilogue
The issue disappeared himself.
Proceeding with the excercise, Xcode IDE underlined some critical points on the view design where I was invited to "click on the icon" to fix; one of this issue was tied to the conflicting contrains.
As suggested by #DonMag, the RatingControl class has to be marked as #IBDesignable (this decorator will be added later on the excercise) to let Xcode immediately view the final result of the custom control. Almost: The stars doesn't appeared and the control doesn't automatically scale adding stars to the control property. This until I closed, opened again and rebuilt several times the whole project.
Differences on tutorial (written for Swift 3.2) and actual Xcode (default project opened in Swift 4 applies.
It's my idea that Apple has to update it's own online documentation to avoid people loose their mind trying to figure out why things doesn't work like expected.
Ignore my first two comments...
In that tutorial, you are adding the custom ratingControl as an arranged subview of a Vertical Stack View. That's why no constraints are needed.
The key is making the class #IBDesignable - that allows Interface Builder and the Auto-Layout engine to use the class' intrinsic size to properly size / position / display it.
(Just a little surprising it's not noted in the tutorial.)
I had the same issue.
Also, the red squares appeared bigger than shown in the tutorial.
For the red squares to accept the constraints of size 44, I had to ensure the RatingControl was positioned inside the stack view, not below.
I'm attaching images for clarification of what I mean by "inside" the stack view.
error reproduced, please note red rectangle outside the stack view hierarchy
error fixed, the red rectangle is inside the stack view hierarchy on the left
The issue is happening because of the total width of all sub views is not equal to the width of StackView.
Using this calculation can fix the problem:
let width = (self.frame.width - self.spacing * CGFloat(starCount-1))/CGFloat(starCount)
let height = self.frame.height
............
for _ in 0..<starCount {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.backgroundColor = UIColor.red
button.heightAnchor.constraint(equalToConstant: height).isActive = true
button.widthAnchor.constraint(equalToConstant: width).isActive = true
button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped(button:)), for: .touchUpInside)
addArrangedSubview(button)
}

Annotation view is not showingUp using objective c

Am getting below error and m,y custom annotation view is not displaying in my iPhone5s device but its displaying in my iPhone6+ device,
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) (
"NSAutoresizingMaskLayoutConstraint:0x12afb36b0 h=--& v=--& H:[MKSmallCalloutView:0x12c0021d0(0)]",
"NSLayoutConstraint:0x12aede9f0 H:|-(0)-[UIView:0x12c008f70] (Names: '|':MKSmallCalloutView:0x12c0021d0 )",
"NSLayoutConstraint:0x12aee0ca0 H:[UIView:0x12c008f70]-(0)-[_MKCalloutAccessoryWrapperView:0x12afc1090]",
"NSLayoutConstraint:0x12aedec30 H:[_MKCalloutAccessoryWrapperView:0x12afc1090]-(12)-[UILabel:0x12c003750'\U00a0']",
"NSLayoutConstraint:0x12aededc0 UIView:0x12c009180.trailing == MKSmallCalloutView:0x12c0021d0.trailing",
"NSLayoutConstraint:0x12aedeeb0 _MKCalloutAccessoryWrapperView:0x12afc6860.trailing == UIView:0x12c009180.leading",
"NSLayoutConstraint:0x12aedef00 UILabel:0x12c003750'\U00a0'.trailing <=
_MKCalloutAccessoryWrapperView:0x12afc6860.leading - 12>" )
Will attempt to recover by breaking constraint
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.
2016-01-27 13:15:49.348 OK[2390:779352] Unable to simultaneously satisfy constraints.
Please help me to get out of this issue.
I had the same issue because the center of the Map was always considered the center of the self.view and not the center of the mapView. You need to set the center of your mapview.

iOS, Animating view's constraints causes error "Unable to simultaneously satisfy constraints"

I am attemptin to animate one of my container view's constraints. In IB, the the view is constrained fine without errors or warnings. When I call these methods in viewDidLoad, to change the views y coordinate like so:
self.queueContainerYConst.constant += 550;
[self.view layoutIfNeeded];
I get the message for "unable to satisfy constraints...". While running the app, my animations and UI look fine, everything is appears to be constrained properly. Here is the entire message I get in the console.
2015-05-03 14:17:52.668 Streamacy[15914:3333195] 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:0x155a95c0 V:|-(614)-[UIView:0x155a83a0] (Names: '|':UIView:0x155a91b0 )>",
"<NSLayoutConstraint:0x155a95f0 V:[UIView:0x155a83a0]-(0)-| (Names: '|':UIView:0x155a91b0 )>",
"<NSLayoutConstraint:0x155af080 'UIView-Encapsulated-Layout-Height' V:[UIView:0x155a91b0(568)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x155a95f0 V:[UIView:0x155a83a0]-(0)-| (Names: '|':UIView:0x155a91b0 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-05-03 14:17:52.684 Streamacy[15914:3333195] 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:0x1566a2a0 UIView:0x156a1900.width == UIView:0x156a1900.height>",
"<NSLayoutConstraint:0x156a9000 V:[UIView:0x156a1900]-(32)-[UIProgressView:0x15688f30]>",
"<NSLayoutConstraint:0x156a0df0 V:[UIProgressView:0x15688f30]-(11)-[MarqueeLabel:0x156a7360'Awake']>",
"<NSLayoutConstraint:0x156a0eb0 UIView:0x1569dd90.trailingMargin == UIView:0x156a1900.trailing + 99>",
"<NSLayoutConstraint:0x156a0f10 UIView:0x156a1900.leading == UIView:0x1569dd90.leadingMargin + 99>",
"<NSLayoutConstraint:0x156a0f40 UIView:0x156a1900.top == UIView:0x1569dd90.topMargin - 46>",
"<NSLayoutConstraint:0x156a92f0 V:[UILabel:0x156a6ea0'Tycho']-(17)-[UITableView:0x1587a000]>",
"<NSLayoutConstraint:0x156a93b0 V:[MarqueeLabel:0x156a7360'Awake']-(2)-[UILabel:0x156a6ea0'Tycho']>",
"<NSLayoutConstraint:0x156a94d0 V:[UITableView:0x1587a000]-(0)-[_UILayoutGuide:0x156a8b20]>",
"<_UILayoutSupportConstraint:0x156a4cf0 V:[_UILayoutGuide:0x156a8b20(0)]>",
"<_UILayoutSupportConstraint:0x156a4810 _UILayoutGuide:0x156a8b20.bottom == UIView:0x1569dd90.bottom>",
"<NSLayoutConstraint:0x156b6070 'UIView-Encapsulated-Layout-Width' H:[UIView:0x1569dd90(320)]>",
"<NSLayoutConstraint:0x156b60a0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x1569dd90(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1566a2a0 UIView:0x156a1900.width == UIView:0x156a1900.height>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-05-03 14:17:52.688 Streamacy[15914:3333195] 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:0x156a9000 V:[UIView:0x156a1900]-(32)-[UIProgressView:0x15688f30]>",
"<NSLayoutConstraint:0x156a0df0 V:[UIProgressView:0x15688f30]-(11)-[MarqueeLabel:0x156a7360'Awake']>",
"<NSLayoutConstraint:0x156a0f40 UIView:0x156a1900.top == UIView:0x1569dd90.topMargin - 46>",
"<NSLayoutConstraint:0x156a92f0 V:[UILabel:0x156a6ea0'Tycho']-(17)-[UITableView:0x1587a000]>",
"<NSLayoutConstraint:0x156a93b0 V:[MarqueeLabel:0x156a7360'Awake']-(2)-[UILabel:0x156a6ea0'Tycho']>",
"<NSLayoutConstraint:0x156a94d0 V:[UITableView:0x1587a000]-(0)-[_UILayoutGuide:0x156a8b20]>",
"<_UILayoutSupportConstraint:0x156a4cf0 V:[_UILayoutGuide:0x156a8b20(0)]>",
"<_UILayoutSupportConstraint:0x156a4810 _UILayoutGuide:0x156a8b20.bottom == UIView:0x1569dd90.bottom>",
"<NSLayoutConstraint:0x156b60a0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x1569dd90(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x156a9000 V:[UIView:0x156a1900]-(32)-[UIProgressView:0x15688f30]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
It appears that everything inside my container view gets misplaced, why?. Am I animating/changing my view improperly?
You're view is over constrained. You have a constraint of 614 to the top and 0 to the bottom of its superview, but the height of that view is 568, so those numbers don't add up. It would be better to only have one of those vertical constraints and a fixed hight for your view if that works for your purposes (that "fixed" height could be made relative to the superview's height if you ned it to adjust for different screen sizes).

Auto Layout is enabled on storyboard but I am still getting AutolayoutMaskContraints

I am trying to do a pure auto layout constraint based app, no autoresizing, and in my storyboard I turn on the flag "Use Auto Layout" in the Xcode 5 File Attributes for the Storyboard and yet I am still getting exceptions. I don't turn on translatesAutoresizingMaskIntoConstraints anywhere in the code. It is my understanding that IB will disable translatesAutoresizingMaskIntoConstraints if auto layout is turned on. Any ideas?
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:0xdca62c0 V:[_UILayoutGuide:0xdca7310]-(201)-[UIView:0xcc69170]>",
"<NSLayoutConstraint:0xdca63e0 V:[UIView:0xcc69170]-(112)-[_UILayoutGuide:0xdc51f50]>",
"<_UILayoutSupportConstraint:0xdc581e0 V:[_UILayoutGuide:0xdca7310(52)]>",
"<_UILayoutSupportConstraint:0xdc97780 V:|-(0)-[_UILayoutGuide:0xdca7310] (Names: '|':UIView:0xdca7240 )>",
"<_UILayoutSupportConstraint:0xdc7e3b0 V:[_UILayoutGuide:0xdc51f50(32)]>",
"<_UILayoutSupportConstraint:0xdc7df20 _UILayoutGuide:0xdc51f50.bottom == UIView:0xdca7240.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0xdcce0c0 h=--& v=--& V:[UIView:0xdca7240(320)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xdca62c0 V:[_UILayoutGuide:0xdca7310]-(201)-[UIView:0xcc69170]>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
It seems that the root view controller for a view has the translatesAutoresizingMaskIntoConstraints turned on all the time. You can see this in the xml in the storyboard file. All the subviews however have the translatesAutoresizingMaskIntoConstraints off. I suspect this is normal behavior, but a bit confusing if you are expecting no translations to occur.

Correctly define constraint for UITableViewCell resizing

i'm currently facing this problem, i need to define a dynamic height UITableViewCell.
The red lines correspond to resizable views (will grow vertically), the blue label have 3 constraints: two for each immediate red views above (>= 8), one more with 170 and lower priority to superview.
The green one has a bottom constraint to the superview (5)
When i try to run my code, it gives me this:
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:0x19d65bb0 V:[UIView:0x19d9a9a0(5)]>",
"<NSLayoutConstraint:0x19d667d0 V:[UILabel:0x19de4180(19)]>",
"<NSLayoutConstraint:0x19d5ba70 V:[UILabel:0x19d61870(19)]>",
"<NSLayoutConstraint:0x19d36df0 V:[UILabel:0x19d36e80(19)]>",
"<NSLayoutConstraint:0x19d35d30 V:[UIView:0x19d36130(0)]>",
"<NSLayoutConstraint:0x19e7b310 V:|-(5)-[UILabel:0x19d6b520] (Names: '|':UITableViewCellContentView:0x19d97580 )>",
"<NSLayoutConstraint:0x17d0b060 V:[UILabel:0x19d6b520]-(5)-[UIView:0x19d9a9a0]>",
"<NSLayoutConstraint:0x17d0a480 V:[UIView:0x19d9a9a0]-(8)-[UILabel:0x19de4180]>",
"<NSLayoutConstraint:0x17d0c920 V:[UILabel:0x19de4180]-(8)-[UILabel:0x19d61870]>",
"<NSLayoutConstraint:0x17d0a100 V:[UILabel:0x19d61870]-(8)-[UIView:0x19d839e0]>",
"<NSLayoutConstraint:0x17d11ad0 V:[UIView:0x19d839e0]-(8)-[UILabel:0x19d36e80]>",
"<NSLayoutConstraint:0x19e742a0 V:[UILabel:0x19d36e80]-(8)-[UILabel:0x19d36770]>",
"<NSLayoutConstraint:0x19ed84a0 V:[UILabel:0x19d36770]-(8)-[UIView:0x19d36130]>",
"<NSLayoutConstraint:0x19e76410 V:[UIView:0x19d36130]-(>=8)-[UILabel:0x19d35560]>",
"<NSLayoutConstraint:0x19ed8af0 V:[UILabel:0x19d35560]-(8)-[UITextView:0x1832ba00]>",
"<NSLayoutConstraint:0x19e7abf0 V:[UITextView:0x1832ba00]-(8)-[UILabel:0x19e7d890]>",
"<NSLayoutConstraint:0x19e83d90 V:[UILabel:0x19e7d890]-(8)-[UITextView:0x18a95e00]>",
"<NSLayoutConstraint:0x19e7b520 V:[UITextView:0x18a95e00]-(5)-| (Names: '|':UITableViewCellContentView:0x19d97580 )>",
"<NSAutoresizingMaskLayoutConstraint:0x19d46fc0 h=--& v=--& V:[UITableViewCellContentView:0x19d97580(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x19d36df0 V:[UILabel:0x19d36e80(19)]>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
So, the question is:
What is the correct way of achieving this???
Are u using storyboard, if yes, simple go to Editor->Resolve Auto Layout Issues->Clear All Constraints In ........ Controller, and then Add Missing Constraints In ...... Controller
It will help you fix the problem of breaking contrainsts between view

Resources