简体   繁体   English

如何为UILabel设置一个又一个的动画

[英]How to animate a UILabel after another

I currently animate two UILabel as such: 我目前为两个UILabel制作动画:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[_temperatureLabel setAlpha:1];
[_tempDescriptionLabel setAlpha:1];
[UIView commitAnimations];

However, I want to show the first label _temperatureLabel then once that is done animating (or maybe halfway through) start animating the second label _tempDescriptionLabel . 但是,我想显示第一个标签_temperatureLabel然后一旦完成动画(或者可能是中途)开始动画第二个标签_tempDescriptionLabel

as I said I'll answer: 正如我所说,我会回答:

 [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{

         //set alpha 1 for first UILabel
         _temperatureLabel.alpha = 1;

        } completion:^(BOOL finished){

        [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{

                //when finished enter here
            //set alpha 1 for second UILabel
            _tempDescriptionLabel.alpha = 1;

            } completion:^(BOOL finished){


            }];

        }];

remember to add QuartzCore framework, and add #import <QuartzCore/QuartzCore.h> 记得添加QuartzCore框架,并添加#import <QuartzCore/QuartzCore.h>

For doing halfWay or any other mid way time, 做半途或任何其他中途时间,

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[_temperatureLabel setAlpha:1];
[UIView commitAnimations];
[self performSelector:@selector(halfWayStart:) withObject:nil afterDelay:1.0];

-(void)halfWayStart:(id)object{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:2.0];
    [_tempDescriptionLabel setAlpha:1];
    [UIView commitAnimations];
}

so, changing the afterDelay time value in performSelector call will help you to start other animation any time. 因此,在performSelector调用中更改afterDelay时间值将帮助您随时启动其他动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM