2013-06-28 37 views
0

我有一個8 imagaviews,我已添加到我的觀點與size (0,0)。現在我想要做的是將每個imageView以UIViewanimation彼此拉開。我想做2個動畫。首先,大小應該去從(0,0) --> (105,85)和結束後的ImageView的大小應該從(105,85) --> (93,75)UIViewanimation animationDidStop方法

現在我有一個方法,在這裏我先放置在正確的place.All我所有的imageViews圖像具有size (0,0)最後我去調用該方法startAnimating

-(void)startAnimating{ 
    [self animageButton:[arrButtons objectAtIndex:0]]; 
} 

然後,第一視圖的動畫(從(0,0) - >(105,85))

-(void)animageButton:(UIImageView *)imgButton{ 
    loopIndex++; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:2.0]; 
    [UIView setAnimationDelegate:self]; 
    CGRect btnFrame = imgButton.frame; 
    btnFrame.size.width = 105; 
    btnFrame.size.height = 85; 
    [UIView transitionWithView:self.view 
         duration:0.5f 
         options:UIViewAnimationOptionCurveEaseIn 
        animations:^{ 
         imgButton.frame = btnFrame; 
        } 
        completion:nil]; 
    [UIView commitAnimations]; 
    [self animageButton2:imgButton]; 


} 

此調用第二個方法(從(105,85 )→(93, 75))

-(void)animageButton2:(UIImageView *)imgButton{ 

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:2.0]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector: @selector(animationDidStop:finished:context:)]; 
    CGRect btnFrame2 = imgButton.frame; 
    btnFrame2.size.width = 93; 
    btnFrame2.size.height = 75; 

    [UIView transitionWithView:self.view 
         duration:0.5f 
         options:UIViewAnimationOptionCurveEaseIn 
        animations:^{ 
         imgButton.frame = btnFrame2; 
        } 
        completion:nil]; 
    [UIView commitAnimations]; 
} 

現在在這一點上,第一個imageView應該是動畫的。現在當動畫完成時。我對此。

-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 
    //do smth 
    if(loopIndex <= 7){ 
     NSLog(@"called"); 
     UIImageView *imgObj = [arrButtons objectAtIndex:loopIndex]; 
     [self animageButton:imgObj]; 
    }else{ 
     NSLog(@"done"); 
     return; 
    } 

} 

它在做什麼,它是在同一時間動畫所有的圖像。但是我希望下一個imageview在之前完成時開始動畫。

任何人都可以幫助我嗎?

+5

你真的應該使用自iOS 4.0('[UIView animateWithDuration:animations:completion]')以來一直存在的更新的動畫方式。它有一個完成後運行動畫的非常簡單的方法。 – borrrden

+0

@borrrden這做到了。但是現在動畫從最低點開始。他們的方式是在imageview的中心啓動它嗎? – Steaphann

+0

查看'CALayer'的'anchorPoint'屬性。如果這沒有幫助,請發佈一個新問題。 – borrrden

回答

0
-(void)startAnimating 
{ 
    NSTimeInterval delay = 0.0; 
    for(UIImageView *imageView in arrButtons) 
    { 
     [self performSelector:@selector(animageButton:) withObject:imageView afterDelay:delay]; 
     delay +=1.0; 
    } 
} 

-(void)animageButton:(UIImageView *)imgButton{ 

    CGRect btnFrame = imgButton.frame; 
    btnFrame.size.width = 105; 
    btnFrame.size.height = 85; 

    [UIView animateWithDuration:0.5f animations:^{ 
     imgButton.frame = btnFrame; 
    } completion:^(BOOL finished) { 
      [self animageButton2:imgButton]; 
    }]; 
} 

-(void)animageButton2:(UIImageView *)imgButton 
{ 
    CGRect btnFrame2 = imgButton.frame; 
    btnFrame2.size.width = 93; 
    btnFrame2.size.height = 75; 

    [UIView animateWithDuration:0.5f animations:^{ 
     imgButton.frame = btnFrame2; 
    } completion:^(BOOL finished) { 

    }]; 
} 

我還沒有測試過代碼。讓我知道是否有任何問題。謝謝。

+0

更新了代碼。 – iCoder