xCode ios5:如何在间隔后淡出标签文本?

xCode ios5:如何在间隔后淡出标签文本?,第1张

概述我有一个显示图像的iOS5应用程序.我点击图片显示其信息.我希望这些信息在几秒钟后消失.有一个很好的方法来做到这一点? 我总是可以实现另一个按钮动作,但这将更整洁.. 谢谢! 使用NSTimer或performSelector:withObject:afterDelay.这两种方法都要求你调用一个单独的方法来实际淡出,这应该是相当简单的. 例: 的NSTimer [NSTimer schedule 我有一个显示图像的iOS5应用程序.我点击图片显示其信息.我希望这些信息在几秒钟后消失.有一个很好的方法来做到这一点?

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

谢谢!

解决方法 使用NSTimer或performSelector: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:如何在间隔后淡出标签文本?全部内容,希望文章能够帮你解决xCode ios5:如何在间隔后淡出标签文本?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1036398.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存