ios检测线角度或度数

Am2*_*710 2 iphone drawing ios uibezierpath

我是iOS的新手,我正在尝试开发一个徒手绘图应用程序,使用uibezierPath.is有一种计算或接收总线长度的方法,即使我绘制直线,曲线或圆形.我在touchmove方法上使用addline,我没有任何控制点.

Cha*_*nte 8

在您的touchesBegan方法中,您可以使用此代码

{
UITouch * touch = [touches anyObject];
CGPoint present = [touch locationInView:self];
CGPoint previous = [touch previousLocationInView:self];
CGFloat angle = [self getAngle:present :previous];
}

- (float) getAngle:(CGPoint)a :(CGPoint)b
{
    int x = a.x;
    int y = a.y;
    float dx = b.x - x;
    float dy = b.y - y;
    CGFloat radians = atan2(-dx,dy);        // in radians
    CGFloat degrees = radians * 180 / 3.14; // in degrees
    return angle;
}
Run Code Online (Sandbox Code Playgroud)

你可以调用任何方法这个方法找到两者之间的夹角CGPointsUIView.

希望这有帮助:-)