0

AM/PM レーンをフェードインおよびフェードアウトさせようとしていますが、両方の方法で機能させることができないようです。

1 つしか使用しない場合は機能しますが、2 つ追加しようとすると、適切なフェード アニメーションなしで前後に反転するだけです。

理由と、これを修正する方法について、誰かが私に洞察を与えることができますか?

以下は私のコードです。

- (void)setState:(MonringNightLabelState)state animated:(BOOL)animated {

    CATransition *animationAM = [CATransition animation];
    animationAM.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animationAM.type = kCATransitionFade;
    animationAM.duration = 0.3;

    CATransition *animationPM = [CATransition animation];
    animationPM.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    animationPM.type = kCATransitionFade;
    animationPM.duration = 0.3;

    if (animated)
    {
        [UIView animateWithDuration:0.3
                              delay:0.0
                            options:UIViewAnimationOptionBeginFromCurrentState
                         animations:^{
                             [self setState:state animated:NO];
                         }
                         completion:^(BOOL finished) {

                         }];
    }

    switch (state)
    {
        case MorningNightLabelStateAM:
        {
            [self.morningNightLabel.layer addAnimation:animationAM forKey:@"kCATransitionFade"];

            self.morningNightLabel.text = @"AM";

        }
            break;
        case MorningNightLabelStatePM:
        {
            [self.morningNightLabel.layer addAnimation:animationPM forKey:@"kCATransitionFade"];

            self.morningNightLabel.text = @"PM";
        }
            break;
    }
}
4

1 に答える 1