I am trying to make this simple layout:
It's just a simple UICollectionViewCell.
But when I put all the auto layout constraints I believe are needed, I get this warning:
NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x17028dd40 H:[UIImageView:0x13fd3b000(48)]>",
"<NSLayoutConstraint:0x17028e2e0 H:|-(8)-[UILabel:0x13fd3bfe0'Something as a title...'] (Names: '|':_UIVisualEffectContentView:0x13fd3ace0 )>",
"<NSLayoutConstraint:0x17028e380 UILabel:0x13fd3bfe0'Something as a title...'.leading == UIImageView:0x13fd3b000.leading>",
"<NSLayoutConstraint:0x17028e470 H:[UIImageView:0x13fd3b000]-(8)-[UILabel:0x13fd3b140'Lady Oracle']>",
"<NSLayoutConstraint:0x17028e4c0 H:[UILabel:0x13fd3b140'Firstname Lastname']-(8)-| (Names: '|':_UIVisualEffectContentView:0x13fd3ace0 )>",
"<NSLayoutConstraint:0x17028e830 H:|-(0)-[UIVisualEffectView:0x13fe0ebd0] (Names: '|':UIView:0x13fe142d0 )>",
"<NSLayoutConstraint:0x17028e8d0 H:[UIVisualEffectView:0x13fe0ebd0]-(0)-| (Names: '|':UIView:0x13fe142d0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x17428ee70 h=-&- v=-&- _UIVisualEffectContentView:0x13fd3ace0.width == UIVisualEffectView:0x13fe0ebd0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x17028fd20 h=--& v=--& H:[UIView:0x13fe142d0(50)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17028dd40 H:[UIImageView:0x13fd3b000(48)]>
As can be inferred from the log I have the following constraints:
bottom container view: bottom, leading and trailing aligned to super view
title: top, leading and trailing spacing to container view. Bottom spacing to user avatar.
user avatar: to have specific size (width & height), horizontal aligned with the title, vertical spacing with the title, bottom space to container.
user name: top aligned to user avatar, leading spacing to user avatar, trailing spacing to container.
I can't seem to have sufficient constraints to make the layout how I want and get rid of the warning. The layout is appearing as expected, though.
There is two thing I can think of:
you forgot to set the views with..
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
your collectionView cell size its to small when the collection view is trying to layout.
Related
I have app with enabled rotation for iPad (iPhone version is rotation-free). In my design, within storyboard, I have this hierarchy: UIView - UIScrollView - UIView. All "views" are set to have full width of the screen. Second UIView has class set to MyView, which is a class with an external xib file. Storyboard and xib are both created in a portrait mode.
Now for the problem.
If I run the app in the landscape mode, all is loaded OK. If I rotate
app after that, all is OK.
If I run the app in the portrait mode, the design "breaks". The entire content is thiner (so there is about 100+ px gap between the end of MyView and the end of the screen). If I rotate app, the design remains broken but correctly "enlarged". The gap is still of the same size. During the first launch, I got the following error in debugger:
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:0x1545b7800 h=-&- v=-&- UIView:0x1546a8cb0.width == ScrollableContentView:0x154575da0.width - 232>",
"<NSLayoutConstraint:0x15458dd80 H:[UIActivityIndicatorView:0x1546afa60]-(370)-| (Names: '|':UIView:0x1546ab840 )>",
"<NSLayoutConstraint:0x15458ddd0 H:|-(361)-[UIActivityIndicatorView:0x1546afa60] (Names: '|':UIView:0x1546ab840 )>",
"<NSLayoutConstraint:0x1546c7080 H:[UIView:0x1546ab840]-(0)-| (Names: '|':UIView:0x1546a8cb0 )>",
"<NSLayoutConstraint:0x1546c7120 H:|-(0)-[UIView:0x1546ab840] (Names: '|':UIView:0x1546a8cb0 )>",
"<NSLayoutConstraint:0x154579710 H:|-(0)-[ScrollableContentView:0x154575da0] (Names: '|':UIScrollView:0x15504c000 )>",
"<NSLayoutConstraint:0x154686ef0 UIScrollView:0x15504c000.centerX == ScrollableContentView:0x154575da0.centerX>",
"<NSLayoutConstraint:0x154697cc0 H:[UIScrollView:0x15504c000]-(0)-| (Names: '|':UIView:0x154547b80 )>",
"<NSLayoutConstraint:0x154697d10 H:|-(0)-[UIScrollView:0x15504c000] (Names: '|':UIView:0x154547b80 )>",
"<NSLayoutConstraint:0x15463b8c0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x154547b80(768)]>"
)
Will attempt to recover by breaking constraint
No matter what I do, I am unable to remove this problem. Even If I deleted almost every constraint I have still the same issue.
You should look if you don't have any auto layout warnings in your storyboard or xib file (yellow/red dot beside your controller name in document outline).
If you don't have any, do you set your constraints when adding your xib view ?
Have you think about content hugging priority or content compression resistance priority ?
What does it mean
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:0x7f871d1303b0 H: [UIButton:0x7f871d197640(30)]>",
"<NSLayoutConstraint:0x7f871d1a1c40 H:[UIButton:0x7f871d196960'LB'(30)]>",
"<NSLayoutConstraint:0x7f871d1a4570 H:[UIView:0x7f871d196d60]-(100.8)-| (Names: '|':UIView:0x7f871ac66870 )>",
"<NSLayoutConstraint:0x7f871d1a5200 H:|-(0)-[UIView:0x7f871d196d60] (Names: '|':UIView:0x7f871ac66870 )>",
"<NSLayoutConstraint:0x7f871d19c5f0 H:[UIView:0x7f871ac66870]-(0)-| (Names: '|':UIView:0x7f871d199d70 )>",
"<NSLayoutConstraint:0x7f871d19c640 H:|-(20)-[UIView:0x7f871ac66870] (Names: '|':UIView:0x7f871d199d70 )>",
"<NSLayoutConstraint:0x7f871d1a8ca0 H:|-(0)-[UIView:0x7f871d199d70] (Names: '|':UIView:0x7f871d199c00 )>",
"<NSLayoutConstraint:0x7f871d1a8d40 UIView:0x7f871d19c820.width == UIView:0x7f871d199d70.width>",
"<NSLayoutConstraint:0x7f871d1a8de0 H:[UIView:0x7f871d199d70]-(10)-[UIView:0x7f871d19c820]>",
"<NSLayoutConstraint:0x7f871d1a8e80 H:[UIView:0x7f871d19c820]-(10)-[UIView:0x7f871d1a7000]>",
"<NSLayoutConstraint:0x7f871d1a8f20 UIView:0x7f871d1a7000.width == UIView:0x7f871d199d70.width>",
"<NSLayoutConstraint:0x7f871d1a8f70 H:[UIView:0x7f871d1a7000]-(0)-| (Names: '|':UIView:0x7f871d199c00 )>",
"<NSLayoutConstraint:0x7f871d1a9450 H:|-(15)-[UIButton:0x7f871d197640] (Names: '|':UIView:0x7f871d19b130 )>",
"<NSLayoutConstraint:0x7f871d1a9540 H:[UIButton:0x7f871d197640]-(10)-[UIView:0x7f871d199c00]>",
"<NSLayoutConstraint:0x7f871d1a95e0 H:[UIView:0x7f871d199c00]-(10)-[UIButton:0x7f871d196960'LB']>",
"<NSLayoutConstraint:0x7f871d1a96d0 H:[UIButton:0x7f871d196960'LB']-(10)-| (Names: '|':UIView:0x7f871d19b130 )>",
"<NSLayoutConstraint:0x7f871d1aa340 H:[UIView:0x7f871d19b130]-(0)-| (Names: '|':UIView:0x7f871d19afc0 )>",
"<NSLayoutConstraint:0x7f871d1aa390 H:|-(0)-[UIView:0x7f871d19b130] (Names: '|':UIView:0x7f871d19afc0 )>",
"<NSLayoutConstraint:0x7f871d1b7230 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f871d19afc0(320)]>"
)
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 <UIKit/UIView.h> may also be helpful.
That means you are giving more constraints than required so it's creates ambiguity.
For example if you have one label having height of 30.
Now you give constraints like top,leading and trailing with constant of 20 and fixed height of 30. that means your label always maintain space of 20 of each side from top,left and right and always keep height of 30.
That's fine.
now if you add one another constraint say fixed width with constant 50 that means label's width should be 50.
Now if your app running on 4 inch device then your screen width is 320.
So, if label maintain width of 50 then can't maintain left and right spacing of 20 and if it maintains spacing of 20 then can't maintain width.
This situation is called ambiguity.
This was an example for understanding.
Your constraints making this kind of ambiguity somewhere, so check twice and remove unnecessary or additional constraints.
hope this will help :)
Probably, something is wrong with constraints for UIView:0x7f871d199d70: as I see, you and/or XCode added offsets and also width.
I have an interface set up with constraints, with a menu bar, collection view, followed by a label, and finally a table view. I am trying to change the width of the collection view via an outlet to the width constraint. However, when I make this change, the collection view seems to move upward and I receive a conflict error. The error says there is a conflict between:
"<_UILayoutSupportConstraint:0x7ff61a519020 V:[_UILayoutGuide:0x7ff61a564eb0(64)]>",
"<_UILayoutSupportConstraint:0x7ff61a555a00 V:|-(0)-[_UILayoutGuide:0x7ff61a564eb0] (Names: '|':UIView:0x7ff61a5620c0 )>",
"<NSLayoutConstraint:0x7ff61a5665e0 V:[_UILayoutGuide:0x7ff61a564eb0]-(0)-[UICollectionView:0x7ff61b05ea00]>",
"<NSAutoresizingMaskLayoutConstraint:0x7ff61a4e1630 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' V:|-(0)-[UIView:0x7ff61a5620c0] (Names: '|':UIViewControllerWrapperView:0x7ff61a70c4e0 )>"
The constraint being broken is
<NSLayoutConstraint:0x7ff61a5665e0 V:[_UILayoutGuide:0x7ff61a564eb0]-(0)-[UICollectionView:0x7ff61b05ea00]>
What is causing this?
I figured out the reason for the error was I was attempting to call layoutIfNeeded within viewDidLoad.
OK, a really simple version of this that breaks...
Create a UIView in a nib.
Add an imageView to it. Give the image view a constraint for an Aspect Ratio of 1:1.
Now add constraints from the image view to the edge of the view. (0 size to pin it to the edges).
Now add the view as a UITableView tableHeaderView.
When you run the application on different devices it will break the constraints and remove the aspect ratio constraint. I don't want this, I want it to change the height of the view to be equal to the width.
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:0x7fad01efbbe0 UIImageView:0x7fad047209b0.width == UIImageView:0x7fad047209b0.height>",
"<NSLayoutConstraint:0x7fad04703630 H:[UIImageView:0x7fad047209b0]-(0)-| (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
"<NSLayoutConstraint:0x7fad04703680 V:|-(0)-[UIImageView:0x7fad047209b0] (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
"<NSLayoutConstraint:0x7fad04703740 V:[UIImageView:0x7fad047209b0]-(0)-| (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
"<NSLayoutConstraint:0x7fad04703790 H:|-(0)-[UIImageView:0x7fad047209b0] (Names: '|':VenueHeaderView:0x7fad047204c0 )>",
"<NSLayoutConstraint:0x7fad0429bcf0 'UIView-Encapsulated-Layout-Height' V:[VenueHeaderView:0x7fad047204c0(300)]>",
"<NSLayoutConstraint:0x7fad0429bca0 'UIView-Encapsulated-Layout-Width' H:[VenueHeaderView:0x7fad047204c0(375)]>" )
Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7fad01efbbe0 UIImageView:0x7fad047209b0.width == UIImageView:0x7fad047209b0.height>
It seems that there are constraints UIView-Encapsulated-Layout-Height being added to the superview. But these are added with the wrong value. It should recalculate these based on the internal constraints of the header view.
I'm trying to customize size of the image inside my UICollectionViewCell,
but I haven't managed to achieve the result yet.
here is my cell
and here is inspector for the height constraint
What am I doing wrong?
Update:
I've just noticed some logs
(
"<NSLayoutConstraint:0x78fcab10 V:[UIImageView:0x78fcaa00(129)]>",
"<NSLayoutConstraint:0x78fcb100 V:|-(8)-[UIImageView:0x78fcaa00] (Names: '|':UIView:0x78fca940 )>",
"<NSLayoutConstraint:0x78fcb130 V:[UILabel:0x78fcac40'Completed all MEDIUM quiz...']-(8)-| (Names: '|':UIView:0x78fca940 )>",
"<NSLayoutConstraint:0x78fcb190 V:[UIImageView:0x78fcaa00]-(8)-[UILabel:0x78fcac40'Completed all MEDIUM quiz...']>",
"<NSAutoresizingMaskLayoutConstraint:0x79195380 h=--& v=--& V:[UIView:0x78fca940(50)]>"
)
But I do not understand how NSAutoresizingMaskLayoutConstraint appears here.
From your screenshot:
you aligned image horizontally and added leading constraint. remove it, if you want to have fixed image size.
if you want your view to automatically resize image (by width) - remove width constraint & horizontal align and add trailing constraint.
It depends on goal.
Hope this helps