在我的应用程序中,有一个图像view.Im将平移手势添加到该图像视图中。
这工作得很好。
图像视图处于横向模式。
我想在用户平移到右方向时增加标签中的计数,而在用户平移到左方向时减少计数。
我用谷歌搜索了很多,但没有找到解决这个问题的办法。
谁能告诉我如何检测用户平移的方向(左/右)?
发布于 2016-06-08 17:21:01
在Swift中我之前的答案
public enum Direction: Int {
case Up
case Down
case Left
case Right
public var isX: Bool { return self == .Left || self == .Right }
public var isY: Bool { return !isX }
}
public extension UIPanGestureRecognizer {
public var direction: Direction? {
let velocity = velocityInView(view)
let vertical = fabs(velocity.y) > fabs(velocity.x)
switch (vertical, velocity.x, velocity.y) {
case (true, _, let y) where y < 0: return .Up
case (true, _, let y) where y > 0: return .Down
case (false, let x, _) where x > 0: return .Right
case (false, let x, _) where x < 0: return .Left
default: return nil
}
}
}https://stackoverflow.com/questions/11777281
复制相似问题