2016-08-06 10 views
1

funktioniert Ich habe ein Stück Code, das ich im View-Controller von Xcode geschrieben. Vor diesem Code funktioniert sogar der Button NEXTTIP. Aber jetzt, nach dem Hinzufügen der Animation, kommt die Animation nicht heraus und die Schaltfläche funktioniert nicht. Bitte Hilfe!„Fade in und out“ Animation nicht

 
 
    @IBAction func nextTip(sender: AnyObject) { 
 
     func hideTip() { 
 
      UIView.animateWithDuration(0.5, 
 
       animations: { 
 
        self.titleLabel.alpha = 0 
 
        self.contentLabel.alpha = 0 
 
        self.imageView.alpha = 0 
 
       }, 
 
       completion: { finished in 
 
        self.showTip 
 
       } 
 
      ) 
 
     } 
 

 
     func showTip() { 
 
      titleLabel.text = "For healthy teeth, don't brush after eating" 
 
      contentLabel.text = "Don't brush your teeth immediately after meals and drinks, especially if they were acidic. Wait 30 to 60 minutes before brushing." 
 
      imageView.image = UIImage(named:"teeth.jpg") 
 
      UIView.animateWithDuration(0.5, 
 
             animations: { 
 
      }) 
 
     } 
 
     
 
    }

+0

Ich kann es nicht funktioniert. – ShibekNet101

Antwort

2

Was Sie in der nextTip() Funktion tun ist zwei neue Funktionen definieren, hideTip() und showTip(). Du rufst sie nicht wirklich an. Das Erstellen von Funktionen innerhalb von Funktionen in Swift ist eine absolut legale Sache, ist aber mit ziemlicher Sicherheit nicht das, was Sie hier tun möchten. Sie müssen die Definitionen für hideTip() und showTip() außerhalb der nextTip(:) Funktion bewegen, so dass Ihr Code wie so strukturiert werden würde:

class MyViewController: UIViewController { 
    func hideTip() { 
     UIView.animateWithDuration(...) 
     // etc. 
    } 

    func showTip() { 
     // stuff 
    } 

    @IBAction func nextTip(sender: AnyObject) { 
     hideTip() 
    } 
} 
+0

ist richtig, Sie müssen Ihre Funktionen außerhalb der IBAction definieren und sie dann darin aufrufen. –