Ios 自动换热器位置设置问题

Ios 自动换热器位置设置问题,ios,objective-c,Ios,Objective C,我以前也发过类似的问题,但我觉得我没有得到正确的答案。基本上,我想将CAShapeLayer的位置更改为移动触摸时触摸的位置。我使用的代码如下所示。我的问题是,动画将工作,但它不会确切地在触摸的位置。取而代之的是,它将有近20个像素的距离。有办法解决这个问题吗 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSSet *allTouches = [event allTouches]; UIto

我以前也发过类似的问题,但我觉得我没有得到正确的答案。基本上,我想将
CAShapeLayer
的位置更改为移动触摸时触摸的位置。我使用的代码如下所示。我的问题是,动画将工作,但它不会确切地在触摸的位置。取而代之的是,它将有近20个像素的距离。有办法解决这个问题吗

   -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches]; 

UItouch *touch = [alltouches objectAtIndex:0];

 CGPoint currentPos = [myTouch locationInView: self];

layer = [self addCircleYellownWithRadius:8 withduration:5 X:currentPos.x Y:currentpos.y];

    }

  -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches]; 

UItouch *touch = [alltouches objectAtIndex:0];

 CGPoint currentPos = [myTouch locationInView: self];
//set layer posotion to touch position
layer.position = CGPointMake(currentPos.x-8,currentPos.y-8);

    }

-(CAShapeLayer *)addCircleYellownWithRadius:(float)radius5 withduration:(float)duration X:(float)x Y:(float)y{
    int radius = (int)radius5;
    CAShapeLayer *circle = [CAShapeLayer layer];
    // Make a circular shape
    circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius)
                                             cornerRadius:radius].CGPath;
    // Center the shape in self.view
    circle.position = CGPointMake(x-radius,
                                  y-radius);



    // Configure the apperence of the circle
    circle.fillColor = [UIColor clearColor].CGColor;
    circle.strokeColor = [UIColor whiteColor].CGColor;
    circle.lineWidth = 5;

    // Add to parent layer
    [self.view.layer addSublayer:circle];

    // Configure animation
    CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    drawAnimation.duration            = duration; // "animate over 10 seconds or so.."
    drawAnimation.repeatCount         = 1.0;  // Animate only once..

    // Animate from no part of the stroke being drawn to the entire stroke being drawn
    drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    drawAnimation.toValue   = [NSNumber numberWithFloat:1.0f];

    // Experiment with timing to get the appearence to look the way you want
    drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    // Add the animation to the circle
    [circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
    CGRect oldFrame = circle.frame;
    circle.anchorPoint = CGPointMake(0.5, 0.5);
   circle.frame = oldFrame;
    return circle;
}

不要转发问题。相反,您应该编辑原始问题,并在原始问题中添加更多信息,以便您可以在原始问题中获得一个好的答案