【发布时间】:2015-08-06 06:20:39
【问题描述】:
我是 Swift 的新手,我想使用 touchesBegan 来停止来自 viewDidAppear 的所有动画,但它不能同时删除 self.view.layer.removeAllAnimatoins() 和加速动画。
我通过将self.view.layer.removeAllAnimatoins() 放在touchesBegan 中来做到这一点,然后将所有 alpha 设置为正常。
这样,
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
self.view.layer.removeAllAnimations()
self.btnO.alpha = 1.0
self.btnX.alpha = 1.0
self.titleMultiplayer.alpha = 1.0
self.questionOX.alpha = 1.0
}
这是另一个加速动画的代码,
import UIKit
import QuartzCore
class ViewController: UIViewController {
@IBOutlet var titleMultiplayer: UILabel!
@IBOutlet var questionOX: UILabel!
@IBOutlet var btnO: UIButton!
@IBOutlet var btnX: UIButton!
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
titleMultiplayer.alpha = 0.0
questionOX.alpha = 0.0
btnO.alpha = 0.0
btnX.alpha = 0.0
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
UIView.animateWithDuration(0.001, animations: {
self.titleMultiplayer.alpha = 1.0
self.btnO.alpha = 1.0
self.btnX.alpha = 1.0
self.questionOX.alpha = 1.0
})
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
UIView.animateWithDuration(4.0, delay: 0.0, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
self.titleMultiplayer.alpha = 1.0
}, completion: nil)
UIView.animateWithDuration(4.0, delay: 2.3, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
self.btnO.alpha = 1.0
}, completion: nil)
UIView.animateWithDuration(4.0, delay: 4.3, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
self.btnX.alpha = 1.0
}, completion: nil)
UIView.animateWithDuration(4.0, delay: 6.3, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
self.questionOX.alpha = 1.0
}, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
}
我想知道viewDidAppear 是否可以做这样的事情。
请帮助并建议我。
非常感谢:]
【问题讨论】:
标签: swift animation touchesbegan viewdidappear