2013-06-28 38 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