gpt4 book ai didi

xCode ios5 : How to fade out a label text after an interval?

转载 作者:行者123 更新时间:2023-12-03 18:20:09 25 4
gpt4 key购买 nike

我有一个显示图像的小 iOS5 应用程序。我单击图像以显示其信息。我希望信息在几秒钟后消失。有没有好的方法来做到这一点?

我总是可以实现另一个按钮操作,但这会更整洁..

谢谢!

最佳答案

使用 NSTimerperformSelector:withObject:afterDelay .这两种方法都要求您调用一个单独的方法,该方法实际上会进行淡出,这应该相当简单。

例子:

NSTimer

[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(fadeOutLabels:) userInfo:nil repeats:NO];

performSelector:withObject:afterDelay:
/* starts the animation after 3 seconds */
[self performSelector:@selector(fadeOutLabels) withObject:nil afterDelay:3.0f];

您将调用方法 fadeOutLabels (或任何你想称它的)
-(void)fadeOutLabels
{
[UIView animateWithDuration:1.0
delay:0.0 /* do not add a delay because we will use performSelector. */
options:UIViewAnimationCurveEaseInOut
animations:^ {
myLabel1.alpha = 0.0;
myLabel2.alpha = 0.0;
}
completion:^(BOOL finished) {
[myLabel1 removeFromSuperview];
[myLabel2 removeFromSuperview];
}];
}

或者您可以使用动画块来完成所有工作:
-(void)fadeOutLabels
{
[UIView animateWithDuration:1.0
delay:3.0 /* starts the animation after 3 seconds */
options:UIViewAnimationCurveEaseInOut
animations:^ {
myLabel1.alpha = 0.0;
myLabel2.alpha = 0.0;
}
completion:^(BOOL finished) {
[myLabel1 removeFromSuperview];
[myLabel2 removeFromSuperview];
}];
}

关于xCode ios5 : How to fade out a label text after an interval?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10097068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com