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