IOS 8 - Find restrictions for UIView with id

I am trying to change the restriction for ImageView for iPhone 4S, 5.5S in viewDidLoad:

for (NSLayoutConstraint *constraint in logoImage.constraints) { if ([constraint.identifier isEqualToString:@"logoTopIdentifier"]) { constraint.constant=10; } } 

It does not seem to even repeat in a loop. Is there any other way to get a specific constraint with id?

+5
source share
2 answers

You can associate a constraint in a storyboard with a view controller class in the same way as you connect a user interface element.

Just find the constraints in your storyboard, make the workspace a split view, and drag the constraint onto the appropriate view controller class.

Sometimes, if you want to animate a change in position, you can update the restriction, for example:

 self.theConstraint?.constant = 100 self.view.setNeedsUpdateConstraints() UIView.animateWithDuration(0.7) { () -> Void in self.view.layoutIfNeeded() } 

block.

That's all.

+4
source

Here is the KVConstraintExtensionsMaster library, with which you can access any constant from view based on NSLayoutAttribute . Regardless of whether this restriction is added Programmatically or from Interface Builder .

  [self.logoImage accessAppliedConstraintByAttribute:NSLayoutAttributeTop completion:^(NSLayoutConstraint *expectedConstraint){ if (expectedConstraint) { expectedConstraint.constant = 10; /* for the animation */ [self.logoImage updateModifyConstraintsWithAnimation:NULL]; } }]; 
+1
source

Source: https://habr.com/ru/post/1237003/


All Articles