我正在尝试通过 UILabels 淡入和淡出来构建我的应用程序的简介。我有两个标签。我希望第一个淡入,在屏幕上停留 4 秒。然后第二个标签应淡入并在屏幕上停留 4 秒。然后它应该淡出两个标签。
我有以下代码,但它没有执行任何操作,因为它直接进入最终状态。我在 viewDidAppear() 中有以下方法。我做错了什么?
-(void) animateLabels
{
[UIView beginAnimations:@"First Label Display" context:nil];
[UIView setAnimationDelay:4.0];
firstLabel.alpha = 1;
[UIView commitAnimations];
[UIView beginAnimations:@"Second Label Display" context:nil];
[UIView setAnimationDelay:6.0];
secondLabel.alpha = 1;
[UILabel commitAnimations];
[UIView beginAnimations:@"Hide Labels" context:nil];
[UIView setAnimationDelay:10.0];
secondLabel.alpha = 0;
firstLabel.alpha=0;
[UILabel commitAnimations];
}
最佳答案
使用基于 block 的动画并将动画链接在一起。所以有3个步骤。 label1 淡入,Label2 淡入,最后 Label3 淡入。我编写了下面的代码来淡入 label1 和 label2。淡出很简单。我想你可以填写其余的内容。从这里开始就很简单了...
试试这个 -
[UIView animateWithDuration:1.0
delay:4
options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^(void)
{
[firstLabel setAlpha:1.0];
}
completion:^(BOOL finished)
{
if(finished)
{
[UIView animateWithDuration:1.0
delay:4.0
options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^(void)
{
[secondLabel setAlpha:1.0];
}
completion:^(BOOL finished)
{
if(finished)
{
//put another block her to hide both the labels.
}
}];
}
}];
关于ios - UILabel 动画淡入淡出不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8216549/