UIView.animateWithDuration(5, animations: {
myLabel.textColor = UIColor.redColor()
})
Label-Textfarbe ändert sich nur sofortIst es möglich, UILabels Textfarbenänderung zu animieren?
UIView.animateWithDuration(5, animations: {
myLabel.textColor = UIColor.redColor()
})
Label-Textfarbe ändert sich nur sofortIst es möglich, UILabels Textfarbenänderung zu animieren?
Versuchen Sie, diese
[UIView transitionWithView:myLabel duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
label.textColor = [UIColor redColor];
} completion:^(BOOL finished) {
}];
danke, es funktioniert;) – mres
Großartig :) Können Sie bitte diese Antwort akzeptieren, indem Sie auf das grüne Häkchen :) –
ich den Code aufschreiben für Objective-C
und Swift
Animationstypen
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);
Codierung für Objective-C
[UIView transitionWithView:myLabel duration:0.20 options: UIViewAnimationOptionTransitionFlipFromBottom animations:^{
myLabel.textColor = [UIColor redColor];
} completion:^(BOOL finished) {
}];
Codierung für Swift
UIView.transition(with: myLabel, duration: 0.20, options: .transitionFlipFromBottom, animations: {() -> Void in
self.myLabel.textColor = UIColor.red
}, completion: {(_ finished: Bool) -> Void in
})
danke, es funktioniert;) – mres
willkommen mein freund, –
Auch wenn Sie die akzeptierte Antwort sagen funktioniert, (1) Sie TransitionCrossDissolve
statt CurveEaseInOut
verwenden müssen; (2) Beim Testen habe ich festgestellt, dass es in Swift so aussieht, als ob Sie eine Unteransicht nicht unmittelbar vor der Animation hinzufügen können. (Ich denke, es ist ein Fehler.)
als myLabel
Sehen erscheint in Ihrem Beispiel lokal zu sein (da globale Variablen als self.myLabel
innerhalb des Blockabschluss geschrieben werden müsste), gibt es eine gute Chance, dass Sie die myLabel
Subview hinzugefügt haben innerhalb der gleichen Methode wie die Animation und ohne eine Verzögerung.
Also, wenn Sie immer noch Probleme auftreten, empfehle ich (1) machen myLabel
global und (2) das Hinzufügen einer Verzögerung zwischen den subview das Hinzufügen und die Animation auf dieser subview Durchführung ex:
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)
}
Nur funktioniert für mich mit NSTimer, danke! – Phil
Oh I‘ Ich bin so blind. Vielen Dank. – mres
Kein Problem, @mres! :) – Undo