【问题标题】:Xcode ViewDidLoad animation SwiftXcode ViewDidLoad 动画 Swift
【发布时间】:2015-09-01 08:51:06
【问题描述】:

我在 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出现。问题是我在第一行中有一个错误告诉我“方法不会覆盖其超类中的任何方法”。那么我该如何做我想要实现的目标呢?

【问题讨论】:

    标签: ios xcode swift animation


    【解决方案1】:

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

    所以它应该是这样的:

    override func viewDidLoad() {
    

    【讨论】:

    • 我很确定它没有,但现在它在下一行给了我一个断点
    【解决方案2】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-01
      • 2015-12-01
      • 2017-05-24
      • 1970-01-01
      相关资源
      最近更新 更多