0
如何在Swift協議中使用UIView.animateWithDuration?當我嘗試使用它,我總是得到:在協議中使用UIView.animateWithDuration
曖昧參考成員 'animateWithDuration(_:延遲:選項:動畫:完成:)'
我怎樣才能獲得參考的UIView(據我所知,animateWithDuration
是靜態方法)?
如何在Swift協議中使用UIView.animateWithDuration?當我嘗試使用它,我總是得到:在協議中使用UIView.animateWithDuration
曖昧參考成員 'animateWithDuration(_:延遲:選項:動畫:完成:)'
我怎樣才能獲得參考的UIView(據我所知,animateWithDuration
是靜態方法)?
由於您無法在協議聲明本身內提供任何實現,因此您應該在默認實現中引用UIView
類。我希望這三個模板案例之一是你需要的:
import UIKit
protocol SomeProtocol {
static func animateWithDuration(duration: NSTimeInterval, delay: NSTimeInterval, options: UIViewAnimationOptions, animations:() -> Void, completion: ((Bool) -> Void)?)
func animateWithDuration(duration: NSTimeInterval, delay: NSTimeInterval, options: UIViewAnimationOptions, animations:() -> Void, completion: ((Bool) -> Void)?)
func someCustomFuncForAnimate()
}
extension SomeProtocol {
static func animateWithDuration(duration: NSTimeInterval, delay: NSTimeInterval, options: UIViewAnimationOptions, animations:() -> Void, completion: ((Bool) -> Void)?) {
UIView.animateWithDuration(duration, delay: delay, options: options, animations: animations, completion: completion)
}
func animateWithDuration(duration: NSTimeInterval, delay: NSTimeInterval, options: UIViewAnimationOptions, animations:() -> Void, completion: ((Bool) -> Void)?) {
UIView.animateWithDuration(duration, delay: delay, options: options, animations: animations, completion: completion)
}
func someCustomFuncForAnimate() {
UIView.animateWithDuration(0.2, delay: 1, options: .TransitionCrossDissolve, animations: {/*...*/}, completion: nil)
}
}
請給我們看你的代碼 – Hamish