Xcode ViewDidLoad动画Swift

时间:2015-09-01 08:51:06

标签: ios xcode swift animation

我在Xcode的标签应用中遇到了动画问题。 我有viewDidLoadviewDidAppear部分,问题是我有两个标签label1label2。我希望label1只在应用程序加载时出现一次,并且每次我返回到FirstView时都会出现label2

所以合乎逻辑的做法是:

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出现并且只消失一次,并且每次label2出现在屏幕上时都会显示firstView。问题是我在第一行有一个错误告诉我“方法不会覆盖其超类中的任何方法”。那么我怎样才能做到我想要实现的目标呢?

2 个答案:

答案 0 :(得分:2)

您必须从viewDidLoad - 方法中删除animated:Bool。这种方法中没有这样的参数。

所以看起来应该是这样的:

override func viewDidLoad() {

答案 1 :(得分:0)

试试这个:

    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
           })
}