Ce que je veux: Après l'appel du Viewcontroller, je veux fondre tous mes éléments dans ce Viewcontroller, sauf pour l'arrière-plan. L'arrière-plan doit rester. Ce qui ne va pas: Comme vous pouvez le voir dans mon code, pour que quelque chose disparaisse, il faut d'abord le supprimer. La partie remove fonctionne très bien. Mais quand je veux que ça ressurgisse, rien ne se passe. Lorsque j'utilise la fonction d'impression pour voir l'alpha d'une étiquette aléatoire, elle est définie sur 1.0. Je ne peux pas comprendre ce que je fais mal.Aucun bouton/étiquette/rien ne réapparaîtra après avoir redéfini l'alpha à 1.0
Voici mon code:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
Removeeverything()
Fadein()
}
func Removeeverything() {
for view in self.view.subviews as [UIView] {
if let btn = view as? UIButton {
UIView.animateWithDuration(0.0, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
btn.alpha = 0.0
}, completion: nil)
}
}
for view in self.view.subviews as [UIView] {
if let btn = view as? UILabel {
UIView.animateWithDuration(0.0, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
btn.alpha = 0.0
}, completion: nil)
}
}
for view in self.view.subviews as [UIView] {
if let btn = view as? UIImageView {
UIView.animateWithDuration(0.0, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
btn.alpha = 0.0
}, completion: nil)
}
}
}
func Fadein() {
Backgrond.alpha = 1.0
for view in self.view.subviews as [UIView] {
if let btn = view as? UIButton {
UIView.animateWithDuration(1.0, delay: 0.0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
btn.alpha = 1.0
}, completion: nil)
}
}
for view in self.view.subviews as [UIView] {
if let btn = view as? UILabel {
UIView.animateWithDuration(1.0, delay: 0.0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
btn.alpha = 1.0
}, completion: nil)
}
}
for view in self.view.subviews as [UIView] {
if let btn = view as? UIImageView {
UIView.animateWithDuration(0.7, delay: 0.0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
btn.alpha = 1.0
}, completion: nil)
}
}
}
Cela aide sûrement à nettoyer le code, merci! Sauf, il va juste disparaître, après les secondes sont en hausse. (Où les secondes sont maintenant 1.0 et 0.7.) Je l'ai testé avec 10 secondes. Il va s'estomper et disparaître automatiquement dans les 10 secondes. Utilisons-nous la mauvaise animation? – Nahaku
Cela fonctionne maintenant, je pense que certaines images ne fonctionnaient pas ... merci beaucoup! – Nahaku