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

objective-c – 淡入,淡出动画到uilabel

发布时间:2020-12-16 05:38:44 所属栏目:百科 来源:网络整理
导读:我有一个标签,我想淡入然后淡出. 这是我的代码: -(void) fadein{ scoreLabel.alpha = 0; [UIView beginAnimations:nil context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; [UIView setAnimationDuration:2]; scoreLabel.alpha = 1; [UI
我有一个标签,我想淡入然后淡出.
这是我的代码:
-(void) fadein
{
    scoreLabel.alpha = 0;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:2];
    scoreLabel.alpha = 1;
    [UIView commitAnimations];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
}



-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished    context:(void *)context {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2];
 scoreLabel.alpha = 0;
[UIView commitAnimations];
}

从这段代码我得到这种情况:我的标签淡入然后我没有看到淡出动画.
我该怎么办呢?

解决方法

-(void) fadein
{
    scoreLabel.alpha = 0;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

    //don't forget to add delegate.....
    [UIView setAnimationDelegate:self];

    [UIView setAnimationDuration:2];
    scoreLabel.alpha = 1;

    //also call this before commit animations......
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView commitAnimations];
}



-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished    context:(void *)context {
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2];
    scoreLabel.alpha = 0;
    [UIView commitAnimations];
}

(编辑:李大同)

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

    推荐文章
      热点阅读