Я пытаюсь добавить ограничение программно в выбранный UITextField внутри UITableViewCell. Он добавлен успешно, и выбранная ширина поля текста увеличивается. Но когда я пытаюсь удалить добавленное ограничение, это не сработает. Может ли кто-нибудь выяснить, где я совершаю ошибку?NSLayoutConstraint не удаляется
-(void)setViewMovedUp:(BOOL)movedUp
{
if (self.currentTextField.tag!=HEADER_FIELD_TAG) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
[self.view bringSubviewToFront:self.currentTextField];
NSLayoutConstraint *constraintTrail = [NSLayoutConstraint constraintWithItem:self.currentTextField.superview
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.currentTextField
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:0.0];
CGRect rect = self.view.frame;
CGRect tableRect = self.currentTextField.frame;
if (movedUp)
{
// 1. move the view's origin up so that the text field that will be hidden come above the keyboard
// 2. increase the size of the view so that the area behind the keyboard is covered up.
[self.currentTextField.superview addConstraint:constraintTrail];
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
rect.size.height += kOFFSET_FOR_KEYBOARD;
tableRect.size.width += 800;
}
else
{
// revert back to the normal state.
[self.currentTextField.superview removeConstraints:@[constraintTrail]];
rect.origin.y += kOFFSET_FOR_KEYBOARD;
rect.size.height -= kOFFSET_FOR_KEYBOARD;
tableRect.size.width -= 800;
}
infoFieldTable.frame = tableRect;
self.view.frame = rect;
[UIView commitAnimations];
}
}