Objective c 需要通过触摸在圆圈中移动UIImageView的帮助吗

Objective c 需要通过触摸在圆圈中移动UIImageView的帮助吗,objective-c,xcode,Objective C,Xcode,我正在设计一个包含线性图的应用程序。我现在看到的是一条有三个点的线:一个在中心,用来移动整条线,另外两个,线的上下,用来旋转。我遇到的问题是,当用户触摸到另外两个点时,如何旋转它们 实际上,我还没有对旋转点做过很多工作,但到目前为止,我的代码如下: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* touch = [touches anyObject]; CGPoint poin

我正在设计一个包含线性图的应用程序。我现在看到的是一条有三个点的线:一个在中心,用来移动整条线,另外两个,线的上下,用来旋转。我遇到的问题是,当用户触摸到另外两个点时,如何旋转它们

实际上,我还没有对旋转点做过很多工作,但到目前为止,我的代码如下:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint point = [touch locationInView:graph];
    if (CGRectContainsPoint(moveDot.frame, point)) {
        moveDotIsTouched = YES;
    }
    if (CGRectContainsPoint(rotateDot1.frame, point)) {
        rotateDot1IsTouched = YES;
    }
    if (CGRectContainsPoint(rotateDot2.frame, point)) {
        rotateDot2IsTouched = YES;
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint point = [touch locationInView:graph];
    if (moveDotIsTouched) {
        if ((point.y > 0) && (point.y < 704))
        {
            if (point.y < 64) {rotateDot1.hidden = YES;}
            else {rotateDot1.hidden = NO;}
            if (point.y > 640) {rotateDot2.hidden = YES;}
            else {rotateDot2.hidden = NO;}
            moveDot.center = CGPointMake(moveDot.center.x, point.y);
            rotateDot1.center = CGPointMake(moveDot.center.x+64, moveDot.center.y-64);
            rotateDot2.center = CGPointMake(moveDot.center.x-64, moveDot.center.y+64);
            graph.base = -(point.y)/32 + 11;
            if (graph.base < 0) {[functionField setText:[NSString stringWithFormat:@"y = %.2fx %.2f", graph.slope, graph.base]];}
            else if (graph.base > 0) {[functionField setText:[NSString stringWithFormat:@"y = %.2fx + %.2f", graph.slope, graph.base]];}
            else {[functionField setText:[NSString stringWithFormat:@"y = %.2fx", graph.slope]];}
            [yintField setText:[NSString stringWithFormat:@"%.2f", graph.base]];
            [self changeTable];
        }
    }
    [graph setNeedsDisplay];
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event
{
UITouch*touch=[触摸任何对象];
CGPoint点=[触摸位置视图:图形];
if(CGRectContainsPoint(moveDot.frame,point)){
movedotisouched=是;
}
if(CGRectContainsPoint(rotateDot1.frame,point)){
rotateDot1IsTouched=是;
}
if(CGRectContainsPoint(rotateDot2.frame,point)){
rotateDot2IsTouched=是;
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件
{
UITouch*touch=[触摸任何对象];
CGPoint点=[触摸位置视图:图形];
如果(移动点触动){
如果((点y>0)和&(点y<704))
{
如果(点y<64){rotateDot1.hidden=YES;}
else{rotateDot1.hidden=NO;}
如果(点y>640){rotateDot2.hidden=YES;}
else{rotateDot2.hidden=NO;}
moveDot.center=CGPointMake(moveDot.center.x,point.y);
rotateDot1.center=CGPointMake(moveDot.center.x+64,moveDot.center.y-64);
rotateDot2.center=CGPointMake(moveDot.center.x-64,moveDot.center.y+64);
graph.base=-(点y)/32+11;
如果(graph.base<0){[functionField setText:[NSString stringWithFormat:@“y=%.2fx%.2f”,graph.slope,graph.base]];}
如果(graph.base>0){[functionField setText:[NSString stringWithFormat:@“y=%.2fx+%.2f”,graph.slope,graph.base]];}
else{[functionField setText:[NSString stringWithFormat:@“y=%.2fx”,graph.slope]];}
[yintField setText:[NSString stringWithFormat:@“%.2f”,graph.base]];
[可自换];
}
}
[图形集需要显示];
}

涉及点定位的数字以像素为单位进行测量。我唯一能想到的旋转外部圆点的方法是计算半径,确保圆点在半径内,但我想知道是否还有比这更简单的方法。有人知道一种简单的方法来将UIImageView移动成一个圆圈吗?

是一种自定义的
UIGestureRecognitor
,用于在iOS应用程序中进行单手指旋转。它跟踪手指围绕中心点的运动。我不知道这是否正是您想要的,但它可能会为您指明正确的方向。

请您更具体地说明您尝试了哪些方法,哪些方法无效?也许可以发布一些您的触摸处理方法?也许你已经拥有的一些东西可以被改编。我甚至不知道从哪里开始。我会发布我的代码,虽然…实际上,这是完美的。我可能不会使用该代码本身,但它是一个很好的参考。谢谢