2013-02-26 80 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