什么是Swift?
我试图找到什么是Swift?,swift,Swift,我试图找到UIPangestureRecognitor的方向 我得到了它的一个扩展,其中一个struct使用OptionSet如下: extension UIPanGestureRecognizer { public struct PanGestureDirection: OptionSet { public let rawValue: UInt8 public init(rawValue: UInt8) { self.rawVa
UIPangestureRecognitor的方向
我得到了它的一个扩展,其中一个struct
使用OptionSet
如下:
extension UIPanGestureRecognizer {
public struct PanGestureDirection: OptionSet {
public let rawValue: UInt8
public init(rawValue: UInt8) {
self.rawValue = rawValue
}
static let Up = PanGestureDirection(rawValue: 1 << 0)
static let Down = PanGestureDirection(rawValue: 1 << 1)
static let Left = PanGestureDirection(rawValue: 1 << 2)
static let Right = PanGestureDirection(rawValue: 1 << 3)
}
private func getDirectionBy(velocity: CGFloat, greater: PanGestureDirection, lower: PanGestureDirection) -> PanGestureDirection {
if velocity == 0 {
return []
}
return velocity > 0 ? greater : lower
}
public func direction(in view: UIView) -> PanGestureDirection {
let velocity = self.velocity(in: view)
let yDirection = getDirectionBy(velocity: velocity.y, greater: PanGestureDirection.Down, lower: PanGestureDirection.Up)
let xDirection = getDirectionBy(velocity: velocity.x, greater: PanGestureDirection.Right, lower: PanGestureDirection.Left)
return xDirection.union(yDirection)
}
}
扩展UIPAngestureRecognitor{
公共结构泛测试方向:OptionSet{
公众出租价值:UInt8
公共初始化(原始值:UInt8){
self.rawValue=rawValue
}
静态松弛=测量方向(原始值:1直接从源:
“向位集提供数学集接口的类型。”
FYI-OptionSet
不是关键字,而是协议的名称。