Reputation: 151
I have uiview with constraints for vertical centring inside superview and for width and height. On rotation of device uiview should always be in center, but I need to have ability to change width of uiview but its position should not be changed. I have tried: - to add leading and trailing constraints but in such case width of uiview is no changing at all - to add constraints for width that it should be greater and less but in such case width is not changed, uiview just moved
Upvotes: 1
Views: 849
Reputation: 4536
If I am understanding the issue correctly, you probably assigned too many constraints on the view so the autolayout system has a conflict and removes some of the constraints and then the ones you want there don't have any effect. I suggest you look into debug output window to see warnings about constraint conflicts and which ones are being removed.
What you want is: remove all the constraints you added on this view, then constraint its leading to the left side of the super view, constraint it to horizontal center inside superview. This way the uiview will be centered, and will resize accordingly. You can also constraint height or constraint the aspect ratio between width and height. What you definitely don't want is to constraint the height and width directly.
Upvotes: 2