我的按钮有一个约束,它应该在superview中水平居中。我试图改变我的约束但没有任何反应。我的想法是,我将按钮移到侧面,然后返回并添加弹性自动化。
- (void)shakeView {
NSLog(@"Shake it baby!");
NSUInteger centerDefault = self.loginButtonHorizontalCenterConstraint.constant;
self.loginButtonHorizontalCenterConstraint.constant = centerDefault + 50;
[self.view layoutIfNeeded];
// self.signInContainerCenterPosition = constraint
self.loginButtonHorizontalCenterConstraint.constant = centerDefault;
[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration:1.5 delay:0.0 usingSpringWithDamping:0.1 initialSpringVelocity:40 options:UIViewAnimationOptionCurveLinear animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
}];
}
所以,我有两个问题。为什么我不能将我的按钮移动到50px的侧面,这是让我的uibutton动摇的可行方法吗?