是否有可能为UILabel的文本颜色变化制作动画?

mre*_*res 6 objective-c ios swift

 UIView.animateWithDuration(5, animations: {
        myLabel.textColor = UIColor.redColor()
    })
Run Code Online (Sandbox Code Playgroud)

标签文字颜色立即改变

Nik*_*wal 11

试试这个

[UIView transitionWithView:myLabel duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
    label.textColor = [UIColor redColor];
} completion:^(BOOL finished) {
}];
Run Code Online (Sandbox Code Playgroud)


Anb*_*hik 5

我写下代码Objective-CSwift

动画类型

typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {
UIViewAnimationOptionCurveEaseInOut            = 0 << 16, // default
UIViewAnimationOptionCurveEaseIn               = 1 << 16,
UIViewAnimationOptionCurveEaseOut              = 2 << 16,
UIViewAnimationOptionCurveLinear               = 3 << 16,

UIViewAnimationOptionTransitionNone            = 0 << 20, // default
UIViewAnimationOptionTransitionFlipFromLeft    = 1 << 20,
UIViewAnimationOptionTransitionFlipFromRight   = 2 << 20,
UIViewAnimationOptionTransitionCurlUp          = 3 << 20,
UIViewAnimationOptionTransitionCurlDown        = 4 << 20,
UIViewAnimationOptionTransitionCrossDissolve   = 5 << 20,
UIViewAnimationOptionTransitionFlipFromTop     = 6 << 20,
UIViewAnimationOptionTransitionFlipFromBottom  = 7 << 20,
} NS_ENUM_AVAILABLE_IOS(4_0);
Run Code Online (Sandbox Code Playgroud)

编码Objective-C

[UIView transitionWithView:myLabel duration:0.20 options: UIViewAnimationOptionTransitionFlipFromBottom animations:^{
myLabel.textColor = [UIColor redColor];

} completion:^(BOOL finished) {
}];
Run Code Online (Sandbox Code Playgroud)

编码Swift

  UIView.transition(with: myLabel, duration: 0.20, options: .transitionFlipFromBottom, animations: {() -> Void in
        self.myLabel.textColor = UIColor.red
    }, completion: {(_ finished: Bool) -> Void in
    })
Run Code Online (Sandbox Code Playgroud)