【问题标题】:CGRectOffset animation not working on ios8 but works on ios7CGRectOffset 动画不适用于 ios8 但适用于 ios7
【发布时间】:2014-12-29 13:44:23
【问题描述】:

我有一个UIView,当检测到向上滑动时,它在animateWithDuration 块中通过CGRectOffset 向上移动。当检测到向下滑动时,相同的视图以相同的方式向下移动。当向下滑动发生并且向下移动动画完成时,我调用另一个方法来动画 UILabel 从左到右摇动。这在我的带有 ios7 的 iphone 5 上完美运行,但在 ios8 上不起作用。有谁知道为什么?我听说 CGRectOffset 不适用于autolayout,但这并不能解释为什么我可以让它在 ios7 而不是 ios8 上工作。

-(void) animatePlayLabel
{
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.1 initialSpringVelocity:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{

    self.playLabel.frame = CGRectOffset(self.playLabel.frame, -10, 0);
    self.playLabel.frame = CGRectOffset(self.playLabel.frame, +20, 0);
    self.playLabel.frame = CGRectOffset(self.playLabel.frame, -20, 0);
    self.playLabel.frame = CGRectOffset(self.playLabel.frame, +20, 0);
    self.playLabel.frame = CGRectOffset(self.playLabel.frame, -20, 0);
    self.playLabel.frame = CGRectOffset(self.playLabel.frame, +20, 0);
    self.playLabel.frame = CGRectOffset(self.playLabel.frame, -10, 0);

    } completion:^(BOOL finished) {

}];

【问题讨论】:

    标签: ios ios7 ios8 autolayout uiviewanimation


    【解决方案1】:

    您应该只在 UIView 动画块内设置 frame 的最终值。您在 iOS 7 中获得所需结果的事实是侥幸 - 您错误地使用了此 API。

    您似乎希望此标签在原地弹跳而不移动。您可以使用 UIDynamics 轻松实现此效果。 (那里有很多示例代码。)

    如果您想对效果进行更细粒度的控制,请查看 Core Animation 的关键帧动画。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多