簡體   English   中英

Xcode ViewDidLoad動畫Swift

[英]Xcode ViewDidLoad animation Swift

我在Xcode的選項卡式應用程序中的動畫遇到了一些麻煩。 我有viewDidLoadviewDidAppear部分,問題是我有兩個標簽label1label2 我希望label1在應用程序加載時僅出現一次,而label2每當我回到FirstView時都出現。

因此,邏輯上的事情是:

override func viewDidLoad(animated: Bool) {
    super.viewDidLoad()

    self.label1.alpha = 0
    self.label2.alpha = 0

    //this is the animation
    UIView.animateWithDuration(2.0, animations: { () -> Void in
        self.label1.alpha = 1.0
        //this is what happens after a delay
        [DELAY CODE]
                self.label1.alpha = 0.0

    })
}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    UIView.animateWithDuration(2.0, animations: { () -> Void in
        self.label2.alpha = 1.0

}

本質上,應該做的是使label1僅出現和消失一次,並且使firstView每次在屏幕上顯示時都出現label2 問題是第一行出現錯誤,告訴我“方法未覆蓋其超類中的任何方法” 那么我該怎么做呢?

您必須從viewDidLoad方法中刪除animated:Bool 此方法中沒有此類參數。

所以它看起來應該像這樣:

override func viewDidLoad() {

嘗試這個 :

    UIView.animateWithDuration(2.0,
                        animations: { () -> Void in

                       // Your animation method
         self.label1.alpha = 1.0

                    }) { (Bool) -> Void in
                        // Call your delay method here.
                        // Delay - 3 seconds

               NSTimer.scheduledTimerWithTimeInterval(NSTimeInterval(3),
                                        target: self, 
                                      selector: "hideLabel", 
                                      userInfo: nil, 
                                       repeats: false)
                    }

//

func hideLabel {

           UIView.animateWithDuration(2,
                  animations: { () -> Void in

                self.label1.alpha = 0.0
           })
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM