Monotouch:UILabel在t秒后消失,如何
如何在 t 秒后隐藏 UILabel?
我可以使用后台线程来执行此操作吗?
先感谢您。问候。
编辑
对于那些感兴趣的人,请遵循卢克的建议:
var timer = NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(5), delegate{
InvokeOnMainThread(delegate{
UIView.BeginAnimations(null);
UIView.SetAnimationDuration(0.5);
UIView.SetAnimationTransition(UIViewAnimationTransition.None, labelToAnimateReference, true);
UIView.SetAnimationDelegate(this);
labelToAnimateReference.Alpha = 0.0f;
UIView.CommitAnimations();
});
});
How is it possible to hide a UILabel after t seconds?
Could I use a background thread to do this?
Thank you in advance. Regards.
EDIT
For those interested in, following Luke advice:
var timer = NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(5), delegate{
InvokeOnMainThread(delegate{
UIView.BeginAnimations(null);
UIView.SetAnimationDuration(0.5);
UIView.SetAnimationTransition(UIViewAnimationTransition.None, labelToAnimateReference, true);
UIView.SetAnimationDelegate(this);
labelToAnimateReference.Alpha = 0.0f;
UIView.CommitAnimations();
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您要更改 UI,所以我建议使用主线程来实际隐藏标签,但是这是可能的:(
其中 t 是您想要隐藏标签的时间的 int!)
编辑
如果您想淡出标签,那么我建议您研究
UIView
动画。在此处查看参考文档。从 iOS 4.0+ 开始,建议您使用 UIView 动画块。
为了适合您的示例,代码将如下所示:
第一个值是动画持续时间。
另请注意,在我使用这些
委托{}
的地方,您还可以执行以下操作:Because you'd be changing the UI, I would suggest using the Main Thread for the actual hiding of the label but yes this is possible:
(where t is an int for the time you'd like to hide the label!)
EDIT
If you want to fade the label out, then I'd suggest looking into
UIView
animations.See reference docs here. As of iOS 4.0+ it is suggested you use UIView animation blocks.
To fit your example, the code would look like this:
The first value is the animation duration.
Just to note as well, where I'm using these
delegate{}
you can also do something like: