nslayoutconstraint

Update the constant property of a constraint programmatically in Swift?

女生的网名这么多〃 提交于 2019-12-17 23:26:17
问题 I want to animate an object, so I declare a constraint and add it to the view. I then update the constant property of the constraint inside an UIView animation. Why doesn't this code move the object? UIView.animateWithDuration(1, animations: { myConstraint.constant = 0 self.view.updateConstraints(myConstraint) }) 回答1: In order to declare an animation, you cannot re-define the constraint and call updateConstraints . You are supposed to change the constant of your constraint and follow the

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

拥有回忆 提交于 2019-12-17 15:53:56
问题 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,

How can I set aspect ratio constraints programmatically in iOS?

陌路散爱 提交于 2019-12-17 10:48:50
问题 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-

How can I set aspect ratio constraints programmatically in iOS?

廉价感情. 提交于 2019-12-17 10:48:04
问题 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-

Auto layout constraints issue on iOS7 in UITableViewCell

本小妞迷上赌 提交于 2019-12-17 02:54:16
问题 I'm using auto layout constraints programmatically to layout my custom UITableView cells and I'm correctly defining the cell sizes in tableView:heightForRowAtIndexPath: It's working just fine on iOS6 and it does look fine in iOS7 as well BUT when I run the app on iOS7, here's the kind of message I see in the console: 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

Can I change multiplier property for NSLayoutConstraint?

时光怂恿深爱的人放手 提交于 2019-12-17 02:29:00
问题 I created two views in one superview, and then added constraints between views: _indicatorConstrainWidth = [NSLayoutConstraint constraintWithItem:self.view1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view2 attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f]; [_indicatorConstrainWidth setPriority:UILayoutPriorityDefaultLow]; _indicatorConstrainHeight = [NSLayoutConstraint constraintWithItem:self.view1 attribute:NSLayoutAttributeHeight relatedBy

Unable to simultaneously satisfy constraints, will attempt to recover by breaking constraint

五迷三道 提交于 2019-12-17 02:02:45
问题 Below is the error message I receive in the debug area. It runs fine and nothing is wrong except that I receive this error. Would this prevent apple accepting the app? How do I fix it? 2012-07-26 01:58:18.621 Rolo[33597:11303] 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

Why does modally presenting a view controller break Auto Layout in my table view?

坚强是说给别人听的谎言 提交于 2019-12-14 03:45:43
问题 Sample Project: http://cl.ly/1o2K2m2r262q I have a UITableView with custom cells that have their height auto-calculated from Auto Layout. The custom cells has three labels within it, each positioned with vertical spacing between one another and the content view, and pushed away from the left side. It works great when I input the data and it loads. However when I modally present a view controller from the view controller hosting the table view, I notice it completely breaks Auto Layout as I

How to remove constraints from all subviews inside my superview?

半腔热情 提交于 2019-12-13 14:24:12
问题 I have a UIView that contains multiple UIView subviews that has its own constraints. How do I remove the subviews' constraints? //only removes the constraints on self.view [self.view removeConstraints:self.view.constraints]; //I get warning: Incompatible pointer types sending 'NSArray *' to parameter of type 'NSLayoutConstraint' [self.subview1 removeConstraints:self.subview1.constraints]; 回答1: Try this code: for (NSLayoutConstraint *constraint in self.view.constraints) { if (constraint

UISearchController issue, NSLayoutAttribute do not work in real device

社会主义新天地 提交于 2019-12-13 12:44:46
问题 When click the searchController 's cancel button, the Searchbar send back too much, I use constraint to solve that, but , NSLayoutAttibute do not work on real device, but only work on sumilator, using UISearchController in my project , there is a strange issue: So I think out a method to solve the issue, in the UISearchBarDelegate delegate method, when cancel (取消) button click, set the top constant to 0 : // MARK: - search delegate func searchBarCancelButtonClicked() { for item