如何在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();
});
});发布于 2011-04-27 08:33:13
由于您将更改UI,我建议使用主线程来实际隐藏标签,但是的,这是可能的:
NSTimer timer = NSTimer.CreateScheduledTimer(t, delegate{
InvokeOnMainThread(delegate{
label.Alpha = 0.0f;
});
});(当你想隐藏标签时,t是一个int!)
编辑如果你想淡出标签,那么我建议看看UIView动画。参见此处的参考文档。对于iOS 4.0+,建议您使用UIView动画块。为了适合您的示例,代码如下所示:
NSTimer timer = NSTimer.CreateScheduledTimer(t, delegate{
InvokeOnMainThread(delegate{
UIView.Animate(0.5f, delegate{
label.Alpha = 0.0f;
});
});
});第一个值是动画持续时间。请注意,在我使用这些delegate{}的地方,您也可以这样做:
NSTimer timer = NSTimer.CreateScheduledTimer(t, FadeLabelOut());
// later on
void FadeLabelOut()
{
// do your stuff here
}https://stackoverflow.com/questions/5801055
复制相似问题