Je suis en train de passer d'une animation entre deux images (UIWindow
backgroundColor
définie à l'aide d'un UIColor
patternImage
). J'ai deux images myImage1
et myImage2
. Je change le UIWindow
backgroundColor
une fois en utilisant la fonction changeImage1()
puis de nouveau en utilisant la fonction changeImage2()
. J'ai également mis le view.backgroundColor = UIColor.clearColor()
afin que je puisse voir ce qui se passe sur le UIWindow
. Code ci-dessous.Modification de l'image UIWindow (backgroundColor en utilisant un UIColor patternImage) avec une animation
Test A:
Quand je change window.backgroundColor = UIColor.redColor()
-window.backgroundColor = UIColor.blueColor()
, je reçois une belle transition sur le UIWindow
entre les couleurs animant rouge au bleu. (Voir le Code A.)
test B:
Cependant quand je mets une image de motif window.backgroundColor = UIColor(patternImage:...)
et appeler changeImage1()
, myImage1
anime bien, mais quand je puis appeler changeImage2()
il n'y a pas d'animation, myImage2
remplace brusquement myImage1
. (Voir le Code B.)
Questions:
1 - Comment puis-je passer avec une animation sur UIWindow entre myImage1
et myImage2
?
2 - Qu'est-ce que je manque dans mon code qui échange simplement les images au lieu d'animer entre eux, pourquoi est-myImage1
animant mais myImage2
n'est pas?
3 - Y at-il d'autres façons d'animer deux images/croix sur la dissolution UIWindow
qui n'utilisent pas UIColor (patternImage: ...)?
code:
A:
func changeImage1() {
self.view.backgroundColor = UIColor.clearColor() //show UIWindow
UIView.animateWithDuration(2, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
if let window = UIApplication.sharedApplication().windows.first as UIWindow! {
window.backgroundColor = UIColor.redColor() //Animation OK
}
}, completion: nil)
}
func changeImage2() {
UIView.animateWithDuration(2, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
if let window = UIApplication.sharedApplication().windows.first as UIWindow! {
window.backgroundColor = UIColor.blueColor() //Animation OK
}
}, completion: nil)
}
B:
func changeImage1() {
self.view.backgroundColor = UIColor.clearColor() //show UIWindow
UIView.animateWithDuration(2, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
if let window = UIApplication.sharedApplication().windows.first as UIWindow! {
window.backgroundColor = UIColor(patternImage: UIImage(named: "myImage1")!) //Animation OK
}
}, completion: nil)
}
func changeImage2() {
UIView.animateWithDuration(2, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
if let window = UIApplication.sharedApplication().windows.first as UIWindow! {
window.backgroundColor = UIColor(patternImage: UIImage(named: "myImage2")!) //NO animation
}
}, completion: nil)
}
En général, une application iOS possède une seule UIWindow et elle est invisible, inchangée et inchangée. Pourquoi faites-vous cela du tout? C'est votre contrôleur de vue racine que l'utilisateur voit à l'arrière de tout; C'est l'endroit pour faire une animation. – matt
@matt Il peut être changé et être vu dans certaines circonstances, c'est pourquoi je tente d'y apporter des modifications. – user4806509
@matt Pas tout à fait vrai. La plupart des applications iOS ont au moins 3 fenêtres - 1 étant utilisé pour afficher la barre d'état et 1 étant utilisé pour afficher le clavier (fenêtres système). Il existe également différents cas d'utilisation lorsque la création d'une nouvelle fenêtre (généralement seulement temporairement) est logique. Cependant, vous avez raison de dire que l'animation d'un changement de fenêtre en fenêtre est impossible. Les animations doivent toujours être effectuées sur des vues à l'intérieur d'une fenêtre, par ex. changer 'alpha' d'une vue. – Sulthan