加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 18:58:08 所属栏目:百科 来源:网络整理
导读:我有一个显示图像的iOS5应用程序.我点击图片显示其信息.我希望这些信息在几秒钟后消失.有一个很好的方法来做到这一点? 我总是可以实现另一个按钮动作,但这将更整洁.. 谢谢! 解决方法 使用NSTimer或performSelector:withObject:afterDelay.这两种方法都要
我有一个显示图像的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];
                     }];
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读