nslayoutconstraint

UIScrollView with iOS Auto Layout Constraints: Wrong size for subviews

会有一股神秘感。 提交于 2019-11-27 20:53:03
I'm trying to generate a view in code. Here's the hierachy of my view object UIScrollView UIView UIButton The ScrollView should be the same size as the window. The button should be as big as possible. I'm using iOS auto layout, so the constraint strings for all of my objects look like this H:|[object]| V:|[object]| I've also set translatesAutoresizingMaskIntoConstraints to NO for each object. The problem is that the button only gets the default button-size. Its parent view object (UIView) only gets the size its subviews need. red: UIScrollView / yellow: UIView How can I force those views to be

activateConstraints: and deactivateConstraints: not persisting after rotation for constraints created in IB

跟風遠走 提交于 2019-11-27 20:27:44
The new NSLayoutConstraint methods activateConstraints: and deactivateConstraints: don't appear to work correctly with IB-created constraints (they do work correctly for code-created constraints). I created a simple test app with one button that has two sets of constraints. One set, which is installed, has centerX and centerY constraints, and the other set, which is uninstalled, has top and left constraints (constant 10). The button method switches these constraints sets. Here is the code, @interface ViewController () @property (strong, nonatomic) IBOutletCollection(NSLayoutConstraint) NSArray

AutoLayout to keep view sizes proportional

一曲冷凌霜 提交于 2019-11-27 18:41:49
I'm trying to achieve the following: I have 2 views in my xib that need to stay 20 pixels off the edge (both sides and top) The 2 views that need to resize aren't the same size They have to be 20 pixels apart Their width needs to stay relative to the width of the parent view I read a tutorial about doing just that and it works but the problem with it is that it requires both views to have the same width and pin Widths equally , which I don't want. Here's what I tried: Add leading space constraint to left view to be 20 pixels Add top space constraint to left view to be 20 pixels Add top space

Why calling setNeedsUpdateConstraints isn't needed for constraint changes or animations?

断了今生、忘了曾经 提交于 2019-11-27 18:12:51
Readings: From this answer : This is what the accepted answer suggests to animate your view changes: _addBannerDistanceFromBottomConstraint.constant = 0 UIView.animate(withDuration: 5) { self.view.layoutIfNeeded() } Why do we call layoutIfNeeded when we aren't changing the frames. We are changing the constraints, so (according to this other answer ) shouldn't we instead be calling setNeedsUpdateConstraints ? Similarly this highly viewed answer says: If something changes later on that invalidates one of your constraints, you should remove the constraint immediately and call

UICollectionView autosize height

时光怂恿深爱的人放手 提交于 2019-11-27 16:59:49
How do I properly resize a UICollectionView so that it fully displays its contents? I have tried many things, including setting its frame, calling reloadData and invalidating the layout: self.collectionView.contentSize = CGSizeMake(300, 2000); self.collectionView.frame = CGRectMake(0, 0, 300, 2000); [self.collectionView reloadData]; [self.collectionView.collectionViewLayout invalidateLayout]; but none of this has any effect. After pressing the button I still see the initial view, like this: I have a small demo program where I have a data source producing 100 elements. In Interface Builder I

How to change or update NSLayoutConstraint programmatically

前提是你 提交于 2019-11-27 13:47:46
问题 I have implemented AutoLayout programmatically using the Code : - (void)addConstraintWithListNavigationViewController:(UIView *)listViewNavigation y:(CGFloat)y height:(CGFloat)height { //WIDTH_ListTableView = 0.4 //set x = 0; NSLayoutConstraint *constraintToAnimate1 = [NSLayoutConstraint constraintWithItem:listViewNavigation attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:0.00 constant:0]; [self.view addConstraint

How can I set aspect ratio constraints programmatically in iOS?

别来无恙 提交于 2019-11-27 13:00:53
I have used auto layout for my view controllers. I have set the V and H positions in constraints, but I want to know how can I increase my button size when it changes to 5s, 6 and 6 Plus. This is the way I added constraints for the login button: NSArray *btncon_V=[NSLayoutConstraint constraintsWithVisualFormat:@"V:[btnLogin(40)]" options:0 metrics:nil views:viewsDictionary]; [btnLogin addConstraints:btncon_V]; NSArray *btncon_POS_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-100-[btnLogin]-100-|" options:0 metrics:nil views:viewsDictionary]; [self.view addConstraints:btncon_POS_H];

What is a 'UIView-Encapsulated-Layout-Width' constraint?

ε祈祈猫儿з 提交于 2019-11-27 11:54:25
问题 I keep getting 'Unable to simultaneously satisfy constraints' exceptions (Xcode 5, iOS 7, both device and simulator), where one of the constraints in the list is something like this: "<NSLayoutConstraint:0x165b23d0 'UIView-Encapsulated-Layout-Width' H:[StoryPlayerCell:0x165affc0(0)]>" I did not set this constraint myself. It's also not an NSAutoresizingMaskLayoutConstraint . But where does it come from? And how can I get rid of it? I have no idea. And I can't find anything about 'UIView

Setting constraints programmatically

落花浮王杯 提交于 2019-11-27 11:41:55
I'm experimenting with how to use UIScrollView. After much trouble, I finally got the hang of it. But now I've seem to hit another snag. In this simple app, I have a scroll view with and in order for it to work, I have to set the view's bottom space to scrollview constraint to 0 as described here and it works fine. I'm doing it through the IB. Now I've come across a scenario where I have to do that part programmatically. I've added the below code in the viewDidLoad method. NSLayoutConstraint *bottomSpaceConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute

When can I activate/deactivate layout constraints?

我的梦境 提交于 2019-11-27 11:37:36
I've set up multiple sets of constraints in IB, and I'd like to programmatically toggle between them depending on some state. There's a constraintsA outlet collection all of which are marked as installed from IB, and a constraintsB outlet collection all of which are uninstalled in IB. I can programmatically toggle between the two sets like so: NSLayoutConstraint.deactivateConstraints(constraintsA) NSLayoutConstraint.activateConstraints(constraintsB) But... I can't figure out when to do that. It seems like I should be able to do that once in viewDidLoad , but I can't get that to work. I've