Ios 是否可以设置UILabel';什么是颜色变化?

Ios 是否可以设置UILabel';什么是颜色变化?,ios,objective-c,swift,Ios,Objective C,Swift,标签文本颜色只是瞬间改变我写下了Objective-C和Swift [UIView transitionWithView:myLabel duration:0.20 options: UIViewAnimationOptionTransitionFlipFromBottom animations:^{ myLabel.textColor = [UIColor redColor]; } completion:^(BOOL finished) { }]; 动画类型 UIView.animate

标签文本颜色只是瞬间改变

我写下了
Objective-C
Swift

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

} completion:^(BOOL finished) {
}];
动画类型

 UIView.animateWithDuration(5, animations: {
        myLabel.textColor = UIColor.redColor()
    })
编码用于
Swift

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

} completion:^(BOOL finished) {
}];
试试这个

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

即使你说接受的答案有效,(1)你需要使用
TransitionCrossDissolve
而不是
CurveEaseInOut
;(2) 在测试过程中,我注意到在Swift中,似乎无法在设置子视图动画之前立即添加子视图。(我认为这是一个错误。)

由于在您的示例中,
myLabel
似乎是局部的(因为全局变量必须在块闭包中写入为
self.myLabel
),因此很有可能您已经在与动画相同的方法中添加了
myLabel
子视图,并且没有延迟

因此,如果仍然遇到问题,我建议(1)使
myLabel
全局化,以及(2)在添加子视图和在该子视图上执行动画之间增加延迟,例如:

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

哦,我真瞎。谢谢。没问题,@mres!:)太好了:)你可以点击绿色的勾号接受这个答案吗:)因为某种原因对我不起作用。在动画过程中,它会突然改变,而不是逐渐改变(我面临着类似的问题。第一个动画变化太快,不尊重间隔。只适用于我与NSTimer,谢谢!提到的错误,在添加子视图后无法立即设置动画,但遗憾的是,它似乎仍然存在。
    self.view.addSubview(myLabel)
    var timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: "animate", userInfo: nil, repeats: false)
}

func animate() {
    UIView.transitionWithView(myLabel, duration: 5.0, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: {
        self.myLabel.textColor = UIColor.redColor()
        }, completion:nil)
}