【问题标题】:Rotate UIView for more than 360 degress with decreasing speed以降低的速度旋转 UIView 超过 360 度
【发布时间】:2013-01-09 17:15:29
【问题描述】:

我有一个 UIView,我想在给定的 T 时间内围绕它的中心点旋转 N 次。并且旋转的速度应该逐渐降低。 (像一个旋转轮)。我有以下代码,但它不能正常工作。

   float T = 5; // 5 seconds
   float rotations = 10;
   //_containerView is the view to be rotate

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:T];
    [UIView setAnimationRepeatCount:0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    CGAffineTransform t = CGAffineTransformRotate(_containerView.transform, (2*M_PI*rotations + 0));
    _containerView.transform = t;
    [UIView commitAnimations];

【问题讨论】:

  • “无法正常工作”……这是怎么回事?

标签: iphone ios objective-c core-animation calayer


【解决方案1】:
#define StartAnimation(duration) [UIView beginAnimations:nil context:NULL];    \
[UIView setAnimationDuration:duration];       \
[UIView setAnimationRepeatAutoreverses:NO];   \
[UIView setAnimationRepeatCount:0]

#define StopAnimation [UIView commitAnimations]

定义这些宏并使用

StartAnimation(<time>)
//your code
StopAnimation

【讨论】:

  • 我认为这应该是一个评论。不是答案。
  • 这不是答案。 :P
  • 通过一次性执行 360 度并执行 n 次并增加时间来做类似的事情,以显示国际象棋棋子移动使用静态 int 来增加时间
  • 你为什么要使用这样的宏?基于块的 API 提供了相同(甚至更多)的功能,但更简洁、更易于理解?
  • 发现它在社交应用中很方便,它为每个事件都有动画
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-01
  • 2012-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-06
相关资源
最近更新 更多