2013-02-26 75 views
1

我在使用UIImageView时遇到摆动动画基础重力影响的麻烦。任何哥们能帮我从这个麻烦中解脱出来吗?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

在此先感谢。

+0

我已经试过几乎所有的动画。但我想我需要应用引力的数学公式.. – 2013-02-27 04:38:11

回答

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]; 

    }] 
+0

嗨jjv360,我想知道如果你能告诉我什么是UIScrollView在容器UIView的滚动手势的单线程。你告诉我你何时在我的问题上发表意见。我正在寻找它,但不久前我删除了这个问题。所以,如果你能回答下面的问题,那将会很棒。谢谢! http://stackoverflow.com/questions/15134684/uiscrollview-inside-uiview-uiview-gesture-one-liner – 2013-02-28 11:46:23