[英]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.