Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用touchMoves事件在objective C中移动使用BezierPath绘制的对象_Ios_Objective C - Fatal编程技术网

Ios 如何使用touchMoves事件在objective C中移动使用BezierPath绘制的对象

Ios 如何使用touchMoves事件在objective C中移动使用BezierPath绘制的对象,ios,objective-c,Ios,Objective C,我正在开发一个iPhone应用程序,在这个应用程序中,我必须绘制一个面具,并使用触摸事件移动它。我在遮罩中有4个点,我必须通过改变点的位置来改变对象的大小 我已经用二次曲线画出了主体部分,但是现在当我更新我的点的位置并且触发一个触摸移动事件时,我的对象的形状变得非常奇怪 请帮帮我,我也在iPhone开发者论坛上读过关于精细变换的文章,但我不确定是否需要使用它,因为我只是在用新的计算点重新绘制对象 下面是示例代码 这是绘制点和精细加工的代码 p_L.x=20.5;

我正在开发一个iPhone应用程序,在这个应用程序中,我必须
绘制一个面具,并使用触摸事件移动它。我在遮罩中有4个点,我必须通过改变点的位置来改变对象的大小

我已经用二次曲线画出了主体部分,但是现在当我更新我的点的位置并且触发一个触摸移动事件时,我的对象的形状变得非常奇怪

请帮帮我,我也在iPhone开发者论坛上读过关于精细变换的文章,但我不确定是否需要使用它,因为我只是在用新的计算点重新绘制对象

下面是示例代码 这是绘制点和精细加工的代码

        p_L.x=20.5;
        p_L.y=30.5;// corner  points
        p_T_M.y=10.5;
        p_T_M.x=60.5;
        p_R.x=100.5;
        p_R.y=30.5;

        p_L_c.x=p_L.x; control points 
        p_L_c.y=p_T_M.y;
        p_R_c.x=p_R.x;
        p_R_c.y=p_T_M.y;
        p_L_c2.x=(p_R.x-p_L.x/2);
        p_L_c2.y=p_R.y+30;


    }//// Bezier Drawing

    bezierPath = [UIBezierPath bezierPath];
    [bezierPath moveToPoint: CGPointMake(CGRectGetMinX(frame) + p_L.x, CGRectGetMinY(frame) + p_L.y)];
    [bezierPath addQuadCurveToPoint:CGPointMake(CGRectGetMinX(frame) +  p_T_M.x, CGRectGetMinY(frame) +  p_T_M.y) controlPoint:CGPointMake(CGRectGetMinX(frame) + p_L_c.x, CGRectGetMinY(frame) + p_L_c.y)];

    [bezierPath addQuadCurveToPoint:CGPointMake(CGRectGetMinX(frame) +  p_R.x, CGRectGetMinY(frame) +  p_R.y) controlPoint:CGPointMake(CGRectGetMinX(frame) + p_R_c.x, CGRectGetMinY(frame) + p_R_c.y)];

    [bezierPath addQuadCurveToPoint:CGPointMake(CGRectGetMinX(frame) +  p_L.x, CGRectGetMinY(frame) +  p_L.y) controlPoint:CGPointMake(CGRectGetMinX(frame) + p_L_c2.x, CGRectGetMinY(frame) + p_L_c2.y)];
    [bezierPath closePath];
    CGContextSaveGState(context);
当我想移动对象时,触摸移动事件中出现了问题

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [touches anyObject];
    CGPoint point=[touch locationInView:self.displayImage];




            if( [[self tapTargetForPath:bezierPath] containsPoint:point]&& move_check==TRUE )
            {
                _displayImage.image=image_TEMP;
                CGPoint diff=CGPointMake(point.x-initial_point.x, point.y-initial_point.y);


                p_L.x=(p_L.x)+diff.x;
                p_L.y=(p_L.y)+diff.y;
                p_T_M.x=(p_T_M.x)+diff.x;
                p_T_M.y=(p_T_M.x)+diff.y;

                p_R.x= (p_R.x)+diff.x;
                p_R.y= (p_R.x)+diff.y;

                p_L_c.x=p_L_c.x+diff.x;
                p_L_c.y=p_L_c.y+diff.y;
                p_R_c.x=p_R_c.x+diff.x;
                p_R_c.y=p_R_c.y+diff.y;
                p_L_c2.x=p_L_c2.x+diff.x;
                p_L_c2.y=p_L_c2.y+diff.x;

                initial_point=point;
                UIGraphicsBeginImageContext(_displayImage.frame.size);
                [image_TEMP drawInRect:CGRectMake(0, 0, _displayImage.frame.size.width, _displayImage.frame.size.height)];

                CGContextRef context = UIGraphicsGetCurrentContext();
                CGRect frame = self.displayImage.bounds;
                bezierPath = [UIBezierPath bezierPath];
                [bezierPath moveToPoint: CGPointMake(CGRectGetMinX(frame) + p_L.x, CGRectGetMinY(frame) + p_L.y)];
                [bezierPath addQuadCurveToPoint:CGPointMake(CGRectGetMinX(frame) +  p_T_M.x, CGRectGetMinY(frame) +  p_T_M.y) controlPoint:CGPointMake(CGRectGetMinX(frame) + p_L_c.x, CGRectGetMinY(frame) + p_L_c.y)];

                [bezierPath addQuadCurveToPoint:CGPointMake(CGRectGetMinX(frame) +  p_R.x, CGRectGetMinY(frame) +  p_R.y) controlPoint:CGPointMake(CGRectGetMinX(frame) + p_R_c.x, CGRectGetMinY(frame) + p_R_c.y)];

                [bezierPath addQuadCurveToPoint:CGPointMake(CGRectGetMinX(frame) +  p_L.x, CGRectGetMinY(frame) +  p_L.y) controlPoint:CGPointMake(CGRectGetMinX(frame) + p_L_c2.x, CGRectGetMinY(frame) + p_L_c2.y)];
                [bezierPath closePath];
                CGContextSaveGState(context);

                _displayImage.image = UIGraphicsGetImageFromCurrentImageContext();
                [_displayImage setImage:_displayImage.image];
            }

        }
如果有人知道怎么做,请帮助我

我要做的基本上就是在这个链接中。。。。

实际上,我使用bezier path for 3 point来提取图像中的一个ROI,我必须使用触摸事件移动这个ROI,并且我必须使用触摸实时调整我的点,所以当我的区域改变点的位置时,它也改变了点的相对距离,因此它破坏了路径的形状,问题是,在xcode中,bezier路径需要一个参考点,我们称之为起点或原点,曲线的所有其他点和控制点也依赖于这个参考点,当有人想在图像上移动一个凹坑时,只需取一个参考点,然后在其中进行更改,并设置其他相对于参考点的点,如

点B.x=2*连续+原点.x; 点b.y=2*contsant+原点y

当所有点都依赖于原点时,您可以移动路径并通过使用原点的旧位置和新旧位置计算所有其他点的新位置来计算其他点的位置。
这是我的解决方案我在stack overflow和Google上搜索了很多人都有这个问题,使用touch在图像上移动路径,但是没有人清楚地回答。他们提出了很多困难和复杂的方法来检查触摸的位置,无论是在路径的内部还是外部,并且都在谈论为了移动而要计算的切线和曲线图像路径我认为这是可能的,就像我做的那样简单,它对我来说很好

您应该提供示例代码,以便能够以有意义的方式提供帮助。这是我的示例代码…Thanx为了获得帮助,我在两天后自己获得了解决方案。您好,您应该添加解决方案并自动接受自己的正确答案。试着解释为什么它能解决问题,等等。