0

我有一个 8imagaviews已添加到我的视图中size (0,0)。现在我想做的是用UIViewanimation. 我想做2个动画。首先,尺寸应该从(0,0) --> (105,85)开始,然后完成后,图像视图的尺寸应该从 (105,85) --> (93,75)

现在我有一个方法,我首先将所有图像视图放在正确的位置。所有图像都有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;
    }

}

它目前正在做的是同时为所有图像设置动画。但我希望下一个图像视图在前一个图像视图完成后开始动画。

谁能帮我这个 ?

4

1 回答 1

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) {

    }];
}

我没有测试过代码。让我知道是否有任何问题。谢谢。

于 2013-06-28T09:10:15.383 回答