![](/img/trans.png)
[英]Swift 3 / Xcode 8.2 - switch view in viewDidLoad not working
[英]Xcode ViewDidLoad animation Swift
我在Xcode的选项卡式应用程序中的动画遇到了一些麻烦。 我有viewDidLoad
和viewDidAppear
部分,问题是我有两个标签label1
和label2
。 我希望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
。 问题是第一行出现错误,告诉我“方法未覆盖其超类中的任何方法” 。 那么我该怎么做呢?
尝试这个 :
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.