/// <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>对数组中最后一个对象的处理 /// </summary> /// <param name="state"></param> public void CircleSetLastObjectWithState(CircleState state) { CircleSet.Last().State = state; }