我正在开发一款iOS / iPad教育应用,可以显示2手(小时和分钟)的时钟。当用户在钟面上旋转时,我想向前或向后移动时间。这将是单指手势或旋转动作。
关于如何判断用户是否在圆形钟面周围顺时针或逆时针旋转手指的任何想法?
我考虑计算角度,然后将角度转换为30度的“部分”。然后观看绊倒的部分的模式。
只是想知道是否有人有一个我不考虑的“whiz bang”解决方案? 也许优雅的东西?
感谢。
答案 0 :(得分:1)
你需要做的是保持至少三个点,然后计算它们形成的“三角形”的面积。
CGPoint a = lastStart;
CGPoint b = start;
CGPoint c = end;
float area = a.x * b.y - a.y * b.x + a.y * c.x - a.x * c.y + b.x * c.y - c.x * b.y;
if(area > 0) {
// you're moving CCW
}
答案 1 :(得分:0)
将手势标称为0,0的起点,并将屏幕划分为四个象限,x和y轴贯穿标称0,0。请注意,依次访问哪些象限。在前两个之后,你有方向性:
Movement into lower right quadrant followed by movement into upper right is counterclockwise
Movement into lower right quadrant followed by movement into lower left is clockwise
Movement into lower left quadrant followed by movement into lower right is counterclockwise
Movement into lower left quadrant followed by movement into upper left is clockwise
Movement into upper left quadrant followed by movement into lower left is counterclockwise
Movement into upper left quadrant followed by movement into upper right is clockwise
etc etc