/// <summary>每添加一个圆,就计算一次方向 /// </summary> public void CalAngleAndconnectTheJumpedCircle() { if (CircleSet == null || CircleSet.Count <= 1) { return; } //取出最后一个对象 PCCircle lastOne = CircleSet.Last(); //倒数第二个 PCCircle lastTwo = CircleSet[CircleSet.Count - 2]; //计算倒数第二个的位置 nfloat last_1_x = lastOne.Center.X; nfloat last_1_y = lastOne.Center.Y; nfloat last_2_x = lastTwo.Center.X; nfloat last_2_y = lastTwo.Center.Y; // 1.计算角度(反正切函数) nfloat angle = (nfloat)(Math.Atan2(last_1_y - last_2_y, last_1_x - last_2_x) + Math.PI / 2); lastTwo.Angle = angle; // 2.处理跳跃连线 CGPoint center = CenterPointWithPointOne(lastOne.Center, lastTwo.Center); PCCircle centerCircle = EnumCircleSetToFindWhichSubviewContainTheCenterPoint(center); if (centerCircle != null) { // 把跳过的圆加到数组中,它的位置是倒数第二个 if (!CircleSet.Contains(centerCircle)) { CircleSet.Insert(CircleSet.Count - 1, centerCircle); } } }
/// <summary> 给一个点,判断这个点是否被圆包含,如果包含就返回当前圆,如果不包含返回的是NULL /// /// </summary> /// <param name="point">前点</param> /// <returns>点所在的圆</returns> public PCCircle EnumCircleSetToFindWhichSubviewContainTheCenterPoint(CGPoint point) { PCCircle centerCircle = null; foreach (PCCircle circle in Subviews) { if (circle.Frame.Contains(point)) { centerCircle = circle; } } if (centerCircle != null && !CircleSet.Contains(centerCircle)) { // 这个circle的角度和倒数第二个circle的角度一致 centerCircle.Angle = CircleSet[CircleSet.Count - 2].Angle; } return(centerCircle); // 注意:NULL,就是当前点不在圆内 }
public override void TouchesMoved(NSSet touches, UIEvent evt) { CurrentPoint = new CGPoint(0, 0); UITouch touch = (UITouch)touches.AnyObject; CGPoint point = touch.LocationInView(this); foreach (PCCircle circle in Subviews) { if (circle.Frame.Contains(point)) { if (!CircleSet.Contains(circle)) { CircleSet.Add(circle); // move过程中的连线(包含跳跃连线的处理) CalAngleAndconnectTheJumpedCircle(); } } else { CurrentPoint = point; } } foreach (PCCircle circle in CircleSet) { circle.State = CircleState.CircleStateSelected; // 如果是登录或者验证原手势密码,就改为对应的状态 (加上这句没有三角箭头) //if (Type != CircleViewType.CircleViewTypeSetting) //{ // circle.State = CircleState.CircleStateLastOneSelected; //} } if (CircleSet.Count > 0) { // 数组中最后一个对象的处理 CircleSetLastObjectWithState(CircleState.CircleStateLastOneSelected); SetNeedsDisplay(); } }