UIViewanimation animationDidStop方法

时间:2013-06-28 09:00:36

标签: ios objective-c uiview uiimageview uiviewanimation

我已使用imagaviews添加了size (0,0)UIViewanimation。现在我想做的是用(0,0) --> (105,85)将每个imageView拉到彼此之后。我想做2个动画。首先,尺寸应该从(105,85) --> (93,75)开始,然后完成后,图像视图尺寸应该来自size (0,0)

现在我有一种方法,我首先将所有的imageView放在正确的位置。所有图像都有startAnimating最后我调用方法-(void)startAnimating{ [self animageButton:[arrButtons objectAtIndex:0]]; }

-(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];


}

然后是第一个视图动画(来自(0,0) - >(105,85))

-(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];
}

这称为第二种方法(来自(105,85) - >(93,75))

-(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应该是动画的。现在动画结束了。我对此。

{{1}}

目前它正在做什么,同时为所有图像制作动画。但我希望下一个imageview在前一个完成后开始制作动画。

任何人都可以帮我吗?

1 个答案:

答案 0 :(得分: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) {

    }];
}

我没有测试过代码。如果有任何问题,请告诉我。感谢。

相关问题