无论如何我们可以在iphone中以摆锤效果旋转图像

时间:2011-06-24 14:34:57

标签: iphone animation

无论如何我们可以使用UIView Animation或CoreAnimation在iphone中以摆锤效果旋转图像

1 个答案:

答案 0 :(得分:1)

使用CGAffineTransformRotate旋转UIImageView,例如

yourImage.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI * (_angle/ 180.0));

此外,您需要在旋转之前在图像上设置定位点,以便可以从正确的位置设置swing。 e.g。

yourImage.layer.anchorPoint = CGPointMake(0.5,0);  // Set anchor to top middle.

显然,您需要设置一个计时器来调整移动图像并控制角度。您可以在计时器中执行以下操作。 (另)

_angle = 45;  // Set starting angle.
_direction = 1; // Set starting direction.
-(void) movePend
{
   if(_direction == 45){
      _direction = 1;
   } else if(_direction == 180) {
     _direction = 0;
   }
   _angle = (_direction) ? _angle-- : _angle++;  // Determine which way to rotate.
    yourImage.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI * (_angle/ 180.0));
}