dynamical view resizing with auto layout - ios

I have a following view hierarchy Main -> Green -> Img
The Green view has the constraints seen in image below
The Img view has the constraints seen in the image below
So when I click the Button the frame of the Green is resized, and so the Img view because of the constraints between them.
But I get an error:
2015-06-07 20:13:07.653 ZoomInZoomOut[7152:1435937] 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) (
"",
"",
"",
"
(Names: '|':UIWindow:0x7fcbd3623630 )>",
"" )
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. 2015-06-07 20:13:07.655
ZoomInZoomOut[7152:1435937] 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) (
"",
"",
"<_UILayoutSupportConstraint:0x7fcbd347fb60 V:[_UILayoutGuide:0x7fcbd3487f80(20)]>",
"<_UILayoutSupportConstraint:0x7fcbd347e3f0 V:|-(0)-[_UILayoutGuide:0x7fcbd3487f80] (Names:
'|':UIView:0x7fcbd3480a20 )>",
"<_UILayoutSupportConstraint:0x7fcbd347dd20 V:[_UILayoutGuide:0x7fcbd34889a0(0)]>",
"<_UILayoutSupportConstraint:0x7fcbd3481700 _UILayoutGuide:0x7fcbd34889a0.bottom == UIView:0x7fcbd3480a20.bottom>",
"",
"
(Names: '|':UIWindow:0x7fcbd3623630 )>",
"" )
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.
The code called when the button is clicked:
#IBAction func buttonClicked(sender: UIButton) {
zoomedView.frame.size.height += 10.0
zoomedView.frame.size.width += 10.0
zoomedView.setTranslatesAutoresizingMaskIntoConstraints(true)
zoomedView.superview?.updateConstraints()
}
From Auto Layout Tutorial Part 2: Constraints I know that this error is caused by conflicting constraints. But I didn't add any new constraints in code behind. In storyboard if I resize the Green view, I get a misplaced view which I fix by updating constraints. That is why I'm trying to achieve in code behind, but get the error from above. Could anyone explain what I'm doing wrong?

Related

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.

getting weird log message on console(AutoLayout)

Hiii Guys,
I have a view with 600*450 size, now i put a collection view in a view with 600*430 size. when i am running application i am getting this weird message on console
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:0x600000285960 V:|-(0)-[UICollectionView:0x7fb133860800] (Names: '|':UIView:0x60000019df60 )>",
"<NSLayoutConstraint:0x600000285a50 V:[UICollectionView:0x7fb133860800]-(20)-| (Names: '|':UIView:0x60000019df60 )>",
"<NSLayoutConstraint:0x600000285dc0 V:[_UILayoutGuide:0x6000001b5b60]-(0)-[UIView:0x60000019dc20]>",
"<NSLayoutConstraint:0x600000285e10 UIView:0x60000019dc20.height == 0.25*UIView:0x60000019db50.height>",
"<NSLayoutConstraint:0x6000002860e0 V:[_UILayoutGuide:0x6000001b5b60]-(0)-[UIView:0x60800019d5a0]>",
"<NSLayoutConstraint:0x600000286180 UIView:0x60000019df60.bottom == UIView:0x60000019ddc0.bottom>",
"<NSLayoutConstraint:0x600000286220 UIView:0x60000019df60.top == UIView:0x60800019d5a0.top>",
"<NSLayoutConstraint:0x600000286540 UIView:0x60000019dcf0.height == 0.25*UIView:0x60000019db50.height>",
"<NSLayoutConstraint:0x600000286590 V:[UIView:0x60000019dc20]-(0)-[UIView:0x60000019dcf0]>",
"<NSLayoutConstraint:0x6000002867c0 UIView:0x60000019ddc0.height == 0.25*UIView:0x60000019db50.height>",
"<NSLayoutConstraint:0x6000002868b0 V:[UIView:0x60000019dcf0]-(0)-[UIView:0x60000019ddc0]>",
"<NSLayoutConstraint:0x600000288d40 'UIView-Encapsulated-Layout-Height' V:[UIView:0x60000019db50(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000285a50 V:[UICollectionView:0x7fb133860800]-(20)-| (Names: '|':UIView:0x60000019df60 )>
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 don't know what to do.
I have applied this 4 constraints to UICollectionView.
This occur because few constraint you have added is not required so it is better to select the view and then after Choose Reset to suggested constraint .
and if after this if constraint not up to mark then better to look for each control constraint and check which constraint showing mark (yellow)and try to remove manually and then add.
Hope it helps.

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).

How to reposition view using swift in iOS?

I am using story board to build ui for my application and uses swift & i have prepared below layout you can see in screen shot.
I want to hide view containing details of stop1 & place stop2 view in place of stop1 at runtime.
I am using following code to hide stop1 & update constraint of stop2
stop1Frame.hidden = true
stop2Frame.updateConstraints()
Please help me.
putting height constraint to 0 of stop1 worked but shows me below error in console.
2015-03-13 17:03:52.738 GroundSpan[5392:1777378] 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:0x7a644500 V:[UILabel:0x7a643d50'Please tap on + button to...'(63)]>",
"<NSLayoutConstraint:0x7a64cb80 V:[UIView:0x7a63aaa0(0)]>",
"<NSLayoutConstraint:0x7a64cc10 UILabel:0x7a632e20'Stop1'.top == UIView:0x7a63aaa0.topMargin>",
"<NSLayoutConstraint:0x7a64d2b0 V:[UILabel:0x7a643d50'Please tap on + button to...']-(20)-| (Names: '|':UIView:0x7a63aaa0 )>",
"<NSLayoutConstraint:0x7a64d310 V:[UILabel:0x7a632e20'Stop1']-(NSSpace(8))-[UILabel:0x7a643d50'Please tap on + button to...']>")
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7a644500 V:[UILabel:0x7a643d50'Please tap on + button to...'(63)]>
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-03-13 17:03:52.739 GroundSpan[5392:1777378] 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:0x7a64cb80 V:[UIView:0x7a63aaa0(0)]>",
"<NSLayoutConstraint:0x7a64cc10 UILabel:0x7a632e20'Stop1'.top == UIView:0x7a63aaa0.topMargin>",
"<NSLayoutConstraint:0x7a64d2b0 V:[UILabel:0x7a643d50'Please tap on + button to...']-(20)-| (Names: '|':UIView:0x7a63aaa0 )>",
"<NSLayoutConstraint:0x7a64d310 V:[UILabel:0x7a632e20'Stop1']-(NSSpace(8))-[UILabel:0x7a643d50'Please tap on + button to...']>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7a64d310 V:[UILabel:0x7a632e20'Stop1']-(NSSpace(8))-[UILabel:0x7a643d50'Please tap on + button to...']>
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.
Create an IBOutlet to the height constraint of stop1 so you can access it in your code.
To hide stop1, set its height constraint to 0, so stop2 will move up.
#IBOutlet weak var stop1HeightConstraint: NSLayoutConstraint!
...
// in your function:
self.stop1HeightConstraint.constant = 0
UIView.animateWithDuration(0.4, animations: {
self.view.layoutIfNeeded()
})
This all assumes that you have setup your autolayout and constraints correctly.

Issue in setting five horizontal buttons in auto layout

I am using auto layout to create five buttons at the bottom of the view.The layout looks like below where the brown colour shows the spacer view and number shows the buttons I am using.
When I set the constraints I find that for iPhone the views are not resizing and we are missing the buttons as in the below screen shot. The buttons are hidden and are not resizing.
When I run it on iPad the last spacer view is resizing and other
Also, there are some errors in the logs that i am unable to understand can see below.
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:0x7f8673d62320 H:[UIView:0x7f8673f08c40]-(398)-| (Names: '|':UIView:0x7f8673f08970 )>",
"<NSLayoutConstraint:0x7f8673d623c0 UIView:0x7f8673f08c40.leading == UIView:0x7f8673f08970.leadingMargin + 86>",
"<NSLayoutConstraint:0x7f8673d7c1e0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f8673f08970(414)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f8673d623c0 UIView:0x7f8673f08c40.leading == UIView:0x7f8673f08970.leadingMargin + 86>
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.
2014-12-29 13:00:54.932 Browser_Test[2480:60168] 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:0x7f8673d62b60 H:|-(446)-[UIView:0x7f8673d48640] (Names: '|':UIView:0x7f8673f08970 )>",
"<NSLayoutConstraint:0x7f8673d62bb0 UIView:0x7f8673f08970.trailingMargin == UIButton:0x7f8673d53450'5'.trailing + 8>",
"<NSLayoutConstraint:0x7f8673d62c00 H:[UIView:0x7f8673d48640]-(0)-[UIButton:0x7f8673d53450'5']>",
"<NSLayoutConstraint:0x7f8673d7c1e0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f8673f08970(414)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f8673d62c00 H:[UIView:0x7f8673d48640]-(0)-[UIButton:0x7f8673d53450'5']>
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.
So can please some body suggest me whats getting wrong.
Edit:1
Edit:2
The buttons should all have pinned width. Button 1 should be set leading to the superview and trailing to spacer 1. Button 5 should be set leading to spacer 4 and trailing to the superview. Other buttons should be set leading and trailing to the adjacent spacers. All of the spacers should be set to have equal width to spacer 1.
Now, autolayout will resize the spacer views, all at the same time, to fill the available space as they don't have a specified width but the buttons do and they also have set edges (for buttons 1 and 5).

Resources