反正有我们可以在iphone一个钟摆效应做图像的旋转 [英] is there anyway we can do rotation of image in a pendulum effect in iphone

查看:109
本文介绍了反正有我们可以在iphone一个钟摆效应做图像的旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正是有,我们可以用在iPhone上钟摆效应做图像的旋转UIView的动画或CoreAnimation

is there anyway we can do rotation of image in a pendulum effect in iphone using UIView Animation or CoreAnimation

推荐答案

使用 CGAffineTransformRotate 旋转你的UIImageView例如

Use CGAffineTransformRotate to rotate your UIImageView e.g.

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

此外,你需要设置锚点您的图像,旋转它之前,这样就可以从正确的位置,使其摆动。例如。

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

显然,您需要设置一个计时器来调整移动图像和控制角度。你可以做这样的事情在一个计时器以下。 (未经测试)

Obviously, you'll need to set up a timer to adjust move the image and control the angle. You could do something like the following in a timer. (untested)

_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));
}

这篇关于反正有我们可以在iphone一个钟摆效应做图像的旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆