【问题标题】:NSLayoutConstraint animation duration in iOS7iOS7中的NSLayoutConstraint动画持续时间
【发布时间】:2014-01-31 13:16:57
【问题描述】:

我不知道如何在 iOS7 中设置 NSLayoutConstraint 动画持续时间。这是我的代码:

self.loadingViewTop.constant = -[[UIScreen mainScreen] bounds].size.height;
self.loadingViewBottom.constant = [[UIScreen mainScreen] bounds].size.height;

[UIView animateWithDuration:30.0f animations:^{
    [self.loadingView setNeedsUpdateConstraints];
}];

【问题讨论】:

  • @iiFreeman 我试过了。实际上,如果您删除 [UIView animateWithDuration] 代码,视图仍然会设置动画。我看不到任何可能的解决方案如何控制它。

标签: objective-c animation ios7 duration nslayoutconstraint


【解决方案1】:

哦,你忘了在动画块中调用[self.view layoutIfNeeded];

【讨论】:

  • 我也试过了。它没有任何区别。我认为布局约束在 iOS7 中表现不同。在 iOS6 中运行良好的代码不再运行。
  • 你检查过你的常量实际上不是 nil 吗?
  • 好的,我搞定了。这是正确的做法: self.loadingViewTop.constant = -[[UIScreen mainScreen] bounds].size.height; self.loadingViewBottom.constant = [[UIScreen mainScreen] bounds].size.height; [UIView animateWithDuration:30.0f 动画:^{ [self.view layoutIfNeeded]; }];
【解决方案2】:

解决办法:

self.loadingViewTop.constant = -[[UIScreen mainScreen] bounds].size.height;
self.loadingViewBottom.constant = [[UIScreen mainScreen] bounds].size.height;

[UIView animateWithDuration:30.0f animations:^{
    [self.view layoutIfNeeded];
}];

【讨论】:

    猜你喜欢
    • 2018-06-15
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多