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

xCode ios5:如何在间隔后淡出标签文本?,xcode,ios5,uilabel,Xcode,Ios5,Uilabel,我有一个iOS5应用程序,可以显示图像。我单击图像以显示其信息。我希望信息在几秒钟后消失。有什么好方法可以做到这一点吗 我总是可以执行另一个按钮操作,但这会更整洁 谢谢 使用NSTimer或performSelector:withObject:afterDelay。这两种方法都需要调用一个单独的方法,该方法将实际执行淡出操作,这应该相当简单 例子: NSTimer [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@

我有一个iOS5应用程序,可以显示图像。我单击图像以显示其信息。我希望信息在几秒钟后消失。有什么好方法可以做到这一点吗

我总是可以执行另一个按钮操作,但这会更整洁


谢谢

使用
NSTimer
performSelector:withObject:afterDelay
。这两种方法都需要调用一个单独的方法,该方法将实际执行淡出操作,这应该相当简单

例子: NSTimer

[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(fadeOutLabels:) userInfo:nil repeats:NO];
性能选择器: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: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];
                     }];
}

这很好,但有一个问题。它适用于第一个图像。但标签不会随后续图像一起恢复。我为自己的无知道歉。。这是一个漫长的生命:)我想我应该为其他人添加-我使用动画块方法,取出removeFromSuperview语句,并在点击图像id之前将myLabel.alpha设置回1.0。同意,回答得很好。代码块。。。一定会喜欢的。如果你收到枚举类型“enum UIViewAnimationCurve”的警告,请将其更改为“UIViewAnimationOptionCurveEaseInOut”
-(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];
                     }];
}