示例#1
0
        /// <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);
                }
            }
        }
示例#2
0
 /// <summary>解锁视图准备
 /// </summary>
 private void LockViewPrepare()
 {
     BackgroundColor = PCCircleViewConst.CircleBackgroundColor;
     for (int i = 0; i < 9; i++)
     {
         PCCircle circle = new PCCircle();
         circle.Type = CircleType.CircleTypeInfo;
         AddSubview(circle);
     }
 }
示例#3
0
        /// <summary> 连线绘制图案(以设定颜色绘制)  将选中的圆形以color颜色链接起来
        /// </summary>
        /// <param name="rect">图形上下文</param>
        /// <param name="color">连线颜色</param>
        public void ConnectCirclesInRect(CGRect rect, UIColor color)
        {
            //获取上下文
            CGContext ctx = UIGraphics.GetCurrentContext();

            // 添加路径
            ctx.AddRect(rect);
            //是否剪裁
            ClipSubviewsWhenConnectInContext(ctx, Clip);
            //剪裁上下文
            ctx.EOClip();
            // 遍历数组中的circle
            for (int index = 0; index < CircleSet.Count; index++)
            {
                // 取出选中按钮
                PCCircle circle = CircleSet[index];
                // 起点按钮
                if (index == 0)
                {
                    ctx.MoveTo(circle.Center.X, circle.Center.Y);
                }
                else
                {
                    // 全部是连线
                    ctx.AddLineToPoint(circle.Center.X, circle.Center.Y);
                }
            }

            // 连接最后一个按钮到手指当前触摸得点
            if (!CurrentPoint.Equals(new CGPoint(0, 0)))
            {
                foreach (var item in Subviews)
                {
                    if (GetCircleState() == CircleState.CircleStateError || GetCircleState() == CircleState.CircleStateLastOneError)
                    {
                        // 如果是错误的状态下不连接到当前点
                    }
                    else
                    {
                        ctx.AddLineToPoint(CurrentPoint.X, CurrentPoint.Y);
                    }
                }
            }

            //线条转角样式
            ctx.SetLineCap(CGLineCap.Round);
            ctx.SetLineJoin(CGLineJoin.Round);
            // 设置绘图的属性
            ctx.SetLineWidth(PCCircleViewConst.CircleConnectLineWidth);
            // 线条颜色
            color.SetColor();
            //渲染路径
            ctx.StrokePath();
        }
示例#4
0
        /// <summary>解锁视图准备
        /// </summary>
        public void LockViewPrepare()
        {
            this.Frame  = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width - PCCircleViewConst.CircleViewEdgeMargin * 2, UIScreen.MainScreen.Bounds.Size.Width - PCCircleViewConst.CircleViewEdgeMargin * 2);
            this.Center = new CGPoint(UIScreen.MainScreen.Bounds.Size.Width / 2, PCCircleViewConst.CircleViewCenterY);
            // 默认剪裁子控件
            Clip = true;
            // 默认有箭头
            Arrow = true;
            this.BackgroundColor = PCCircleViewConst.CircleBackgroundColor;

            for (int i = 0; i < 9; i++)
            {
                PCCircle circle = new PCCircle();
                circle.Type  = CircleType.CircleTypeGesture;
                circle.Arrow = Arrow;
                AddSubview(circle);
            }
        }
示例#5
0
        /// <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,就是当前点不在圆内
        }