我不熟悉iOS动画,下面是我的问题:
在我们应用程序的登录屏幕上,有一个登录按钮。当单击该按钮时,我们需要将其向上移动,然后更改其标题。向上移动是这样的动画:
[UIView animateWithDuration:0.5
animations:^{
loginButton.frame = newLoginButtonFrame;
}
completion:^ (BOOL finished) {
}];这如预期的那样起作用。
然后,在尝试更改完成回调中的标题后,如下所示:
[UIView animateWithDuration:0.5
animations:^{
loginButton.frame = newLoginButtonFrame;
}
completion:^ (BOOL finished) {
[loginButton setTitle:@"Cancel" forState:UIControlStateNormal];
}];有些奇怪的事情发生了:按钮“跳”回原来的位置,好像动画被取消了一样。
这里发生什么事情?
发布于 2015-09-15 14:19:17
如果您使用的是自动布局,您应该动画约束,而不是框架。例如,您可以为底部约束设置一个出口,并设置如下动画:
viewBottomConstraint.constant = 32;
[UIView animateWithDuration:0.5
animations:^{
[self.view layoutIfNeeded]; // Called on parent view
}];
}您可以在文档这里中找到更多信息。
https://stackoverflow.com/questions/32588242
复制相似问题