UIImageView上的摆动画

时间:2013-02-26 09:48:03

标签: iphone ios objective-c

我在我的UIImageView上应用摆动动画基础重力效果时遇到了麻烦。任何哥们能帮助我摆脱这个麻烦吗?

我试过下面的源代码。但是因为引力不适用。

- (void)swingPendulum {
 pendulum.layer.anchorPoint = CGPointMake(0.5,0);

[pendulum.layer setTransform:CATransform3DMakeRotation(-M_PI*3/4, 0, 0, 1)];
CABasicAnimation *needleAnim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
needleAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
needleAnim.duration = 1;
needleAnim.repeatCount = 5;
needleAnim.autoreverses = YES;
// Setting fillMode means that, once the animation finishes, the needle stays in its end position.
needleAnim.fillMode = kCAFillModeForwards;
needleAnim.removedOnCompletion = YES;
needleAnim.toValue = [NSNumber numberWithFloat:M_PI*3/4];
 [pendulum.layer addAnimation:needleAnim forKey:nil];
}

实际上我们需要动画......

看看这个:http://blog.ruben-martins.co.uk/2010/02/maya-tutorials-pendulum-animation.html

先谢谢。

1 个答案:

答案 0 :(得分:0)

如果你的图像上面有一个空白的顶部并且从中间开始并且只想旋转它(还没试过它):

-(void) doAnimation {

    imgView.transform = CGAffineTransformMakeRotation(-0.7);
    [UIView animateWithDuration:4 delay:0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAutoreverse animations:^{

        imgView.transform = CGAffineTransformMakeRotation(0.7);

    } completion:^{

        [self doAnimation];

    }]