2013-04-04 44 views
0

我有一個問題,我想在水平滾動視圖中對圖像進行一點旋轉動畫。他們應該在滑入和滑出時旋轉。有沒有人有任何想法如何做到這一點?當我滾動時,我希望它們旋轉。在圖像上的水平滾動視圖中的旋轉動畫Obj-c

我用盡的東西,但是當我滾動(僅第一個圖像)不旋轉 我做了這樣的事情:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    int page = scrollView.contentOffset.x/scrollView.frame.size.width; 
    UIImageView *view = [scrollView.subviews objectAtIndex: page]; 

    if(scrollView.contentOffset.x > lastX) 
    { 
     NSLog(@"scroll right"); 
     [view setTransform: CGAffineTransformMakeRotation(M_PI/scrollView.contentOffset.x + 0.1)]; 

    } 
    else if(scrollView.contentOffset.x < lastX) 
    { 
     NSLog(@"scroll left"); 
     [view setTransform: CGAffineTransformMakeRotation(M_PI/scrollView.contentOffset.x - 0.1)]; 
    } 
    else 
    { 
    } 
+0

但是,您可以使用scrollview的contentOffset的x座標。 – yinkou 2013-04-04 09:57:16

回答

0

你可以使用CGAffineTransformRotate。 但是在你必須設置imageView的錨點之前。默認情況下,它被設置爲(0.5,0.5),即圖像將從中心旋轉。

[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
    imageView.transform= CGAffineTransformMakeRotation(degreeInRadians); // -- 2 -- 
} completion:^(BOOL finished){ 
    // left blank 
}]; 
+0

在動畫塊中旋轉一定程度,如imageView.transform = CGAffineTransformMakeRotation(-pi/3);然後在完成塊中將其旋轉回正常狀態,如[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^ {imageObjects.transform = CGAffineTransformMakeRotation(0); } completion:nil]; – 2013-04-04 10:47:10

+0

我想滾動時圖像旋轉。不只是一次。 – Jojo 2013-04-04 13:26:03