swift 如何在扩展中使用枚举
swift how to use enum in extension
如何在带有扩展名的 CALayer 中添加某种类型的 CAMediaTimingFunction
extension CALayer{
enum easings {
case easeIn01
case easeOut01
}
var ease: easings{
switch self.ease {
case .easeIn01:
return (CAMediaTimingFunction(controlPoints: 0.47, 0, 0.745, 0.715))
case .easeOut01:
return (CAMediaTimingFunction(controlPoints: 0.39, 0.575, 0.565, 1))
}
}
}
我假设您想为您的恒定计时函数创建 "shortcut"。
extension CALayer {
enum Easings {
case easeIn01
case easeOut01
var timing: CAMediaTimingFunction {
switch self {
case .easeIn01:
return CAMediaTimingFunction(controlPoints: 0.47, 0, 0.745, 0.715)
case .easeOut01:
return CAMediaTimingFunction(controlPoints: 0.39, 0.575, 0.565, 1)
}
}
}
}
/// To get easing
CALayer.Easings.easeIn01
/// To get timing function
CALayer.Easings.easeIn01.timing
如何在带有扩展名的 CALayer 中添加某种类型的 CAMediaTimingFunction
extension CALayer{
enum easings {
case easeIn01
case easeOut01
}
var ease: easings{
switch self.ease {
case .easeIn01:
return (CAMediaTimingFunction(controlPoints: 0.47, 0, 0.745, 0.715))
case .easeOut01:
return (CAMediaTimingFunction(controlPoints: 0.39, 0.575, 0.565, 1))
}
}
}
我假设您想为您的恒定计时函数创建 "shortcut"。
extension CALayer {
enum Easings {
case easeIn01
case easeOut01
var timing: CAMediaTimingFunction {
switch self {
case .easeIn01:
return CAMediaTimingFunction(controlPoints: 0.47, 0, 0.745, 0.715)
case .easeOut01:
return CAMediaTimingFunction(controlPoints: 0.39, 0.575, 0.565, 1)
}
}
}
}
/// To get easing
CALayer.Easings.easeIn01
/// To get timing function
CALayer.Easings.easeIn01.timing