首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIViewanimation animationDidStop方法

UIViewanimation animationDidStop方法
EN

Stack Overflow用户
提问于 2013-06-28 17:00:36
回答 1查看 656关注 0票数 0

我使用size (0,0)将一个8 imagaviews添加到我的视图中。现在我想要做的是用一个UIViewanimation一个接一个地拉取每个imageView。我想做两个动画。首先,图像视图的大小应该从(0,0) --> (105,85)转到,完成后,图像视图的大小应该从(105,85) --> (93,75)转到

现在我有了一个方法,我首先把所有的imageViews放在正确的place.All上,图像最后有size (0,0),我调用这个方法startAnimating

代码语言:javascript
复制
-(void)startAnimating{
    [self animageButton:[arrButtons objectAtIndex:0]];
}

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

代码语言:javascript
复制
-(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))

代码语言:javascript
复制
-(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应该是动画了。现在,当动画结束时。我同意这一点。

代码语言:javascript
复制
-(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;
    }

}

它现在所做的就是同时为所有的图像添加动画。但我希望下一个图像视图在前一个图像视图完成后开始动画。

有人能帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2013-06-28 17:10:15

代码语言:javascript
复制
-(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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17360961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档