Fade In Fade Out Animation

后端 未结 13 1146
生来不讨喜
生来不讨喜 2021-01-30 01:45

Here is some code I struggle with for a while.

If you start the fade in animation, the label text fades in. If I start the fade out animation the the label text fades ou

13条回答
  •  生来不讨喜
    2021-01-30 01:55

    labelAnimate = (UILabel*) [self.view viewWithTag:101];
    btnTapMe = (UIButton*) [self.view viewWithTag:100];
    [btnTapMe addTarget:self action:@selector(startAnimating:) forControlEvents:UIControlEventTouchUpInside];
    
    //////////////
    
    -(void) startAnimating:(UIButton*)button {
        [labelAnimate setAlpha:0.0];
        [NSTimer scheduledTimerWithTimeInterval:1.8 target:self selector:@selector(continuousEaseInOut) userInfo:button repeats:YES];
    }
    
    -(void) continuousFadeInOut {
        [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
            [labelAnimate setAlpha:1.0];
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                [labelAnimate setAlpha:0.0];
            } completion:nil];
        }];
    }
    

提交回复
热议问题