【问题标题】:fade in, fade out animation to uilabel淡入淡出动画到uilabel
【发布时间】:2012-07-06 07:16:07
【问题描述】:

我有一个要淡入然后淡出的标签。 这是我的代码:

-(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];
}

从这段代码中我得到了这种情况:我的标签淡入,然后我看不到淡出动画。 我该如何解决?

【问题讨论】:

    标签: objective-c xcode animation uilabel


    【解决方案1】:
    -(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];
    }
    

    【讨论】:

    • 谢谢!我忘了使用 setAnimationDelagate,现在它可以完美运行了!
    【解决方案2】:

    对setAnimationDidStopSelector 的调用应该在提交动画之前:

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:2];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    
    scoreLabel.alpha = 1;
    
    [UIView commitAnimations];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-20
      • 2012-12-18
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      相关资源
      最近更新 更多