Wednesday, 28 August 2013

NSContraintLayout does not get removed

NSContraintLayout does not get removed

pI have four simple NSLayoutConstraints to programmatically modify a NIB
layout. Yet altough I am able to insert them so modifying the layout,
nothing happens when I remove them, while I would expect the original
format to emerge again. That is my simple piece of code:/p precode[UIView
animateWithDuration:.6 animations:^{ if (show){ [self.view
removeConstraint:topConstraint]; [self.view
removeConstraint:leftConstraint]; [self.view
removeConstraint:bottomConstraint]; [self.view
removeConstraint:rightConstraint]; } else { [self.view
addConstraint:topConstraint]; [self.view addConstraint:leftConstraint];
[self.view addConstraint:bottomConstraint]; [self.view
addConstraint:rightConstraint]; }[self.view layoutIfNeeded]; } completion
:^(BOOL finished){ for (ImageToDrag* cursor in appDelegate.favorites){
[cursor setFrame:CGRectMake(cursor.frame.origin.x, (show?[cursor
favoritePosition]-cursor.frame.size.height/2:self.view.bounds.origin.y-200),
cursor.frame.size.width, cursor.frame.size.height)]; } }]; /code/pre
pWhile the layout, created in the init of the class are:/p
precodetopConstraint = [NSLayoutConstraint constraintWithItem:appendino
attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual
toItem:self.backStatus attribute:NSLayoutAttributeBottom multiplier:1.0
constant:0]; topConstraint.priority=1000; leftConstraint =
[NSLayoutConstraint constraintWithItem:left
attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual
toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0
constant:0]; leftConstraint.priority=1000; bottomConstraint =
[NSLayoutConstraint constraintWithItem:bottom
attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual
toItem:self.fondino attribute:NSLayoutAttributeTop multiplier:1.0
constant:0]; bottomConstraint.priority=1000; rightConstraint =
[NSLayoutConstraint constraintWithItem:right
attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual
toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0
constant:0]; rightConstraint.priority=1000; /code/pre pAnother constraint
on the same layout works seamlessly./p pI tried leaving just one
constraint as well as taking the code out of the animation to no avail.
Might it be that some constraint may not be reversible, for some funny
reason? Really a creepy thought, though./p

No comments:

Post a Comment