[英]Xcode ViewDidLoad animation Swift
I'm having some trouble with the animations in a tabbed app in Xcode. 我在Xcode的选项卡式应用程序中的动画遇到了一些麻烦。 I have the viewDidLoad
and the viewDidAppear
parts, the problem is that I have two labels label1
and label2
. 我有viewDidLoad
和viewDidAppear
部分,问题是我有两个标签label1
和label2
。 I would like label1
appearing only once when the application loads, and label2
appearing every time I go back to the FirstView. 我希望label1
在应用程序加载时仅出现一次,而label2
每当我回到FirstView时都出现。
So the logical thing to do would be: 因此,逻辑上的事情是:
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
}
Essentially what this should do is make label1
appear and disappear only once, and make label2
appear every time firstView
shows up on the screen. 本质上,应该做的是使label1
仅出现和消失一次,并且使firstView
每次在屏幕上显示时都出现label2
。 The problem is that I have an error in the first line telling me "Method does not override any method from its superclass" . 问题是第一行出现错误,告诉我“方法未覆盖其超类中的任何方法” 。 So how can I do what I am trying to achieve? 那么我该怎么做呢?
You have to remove the animated:Bool
from your viewDidLoad
-method. 您必须从viewDidLoad
方法中删除animated:Bool
。 there is no such parameter in this method. 此方法中没有此类参数。
So it should look like that: 所以它看起来应该像这样:
override func viewDidLoad() {
Try This : 尝试这个 :
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.