【问题标题】:BezierPath Rotation in a UIViewUIView 中的 BezierPath 旋转
【发布时间】:2012-05-10 12:17:16
【问题描述】:

我正在绘制 BezierPath on Touch 事件。现在我必须使用手势方法在同一位置旋转该贝塞尔路径。但问题是,旋转后它的位置会发生变化。它看起来像下图......我该如何解决这个问题?

上图为原图。 和我分享你的想法。。 提前致谢

【问题讨论】:

    标签: iphone ios uigesturerecognizer bezier uibezierpath


    【解决方案1】:

    Apple documentation.查看这个

    applyTransform: 使用指定的仿射变换矩阵变换路径中的所有点。

    - (void)applyTransform:(CGAffineTransform)transform
    

    这个我没试过。但这里是如何从链接rotating-nsbezierpath-objects 旋转NSBezierPath。尝试在UIBezierPath 上使用类似的方法。

    - (NSBezierPath*)rotatedPath:(CGFloat)angle aboutPoint:(NSPoint)cp
    {
    // return a rotated copy of the receiver. The origin is taken as point <cp> relative to the original path.
    // angle is a value in radians
    
    if( angle == 0.0 )
      return self;
    else
    {
      NSBezierPath* copy = [self copy];
    
      NSAffineTransform* xfm = RotationTransform( angle, cp );
      [copy transformUsingAffineTransform:xfm];
    
      return [copy autorelease];
    }
    }
    

    使用:

    NSAffineTransform *RotationTransform(const CGFloat angle, const NSPoint cp)
    {
    // return a transform that will cause a rotation about the point given at the angle given
    
    NSAffineTransform* xfm = [NSAffineTransform transform];
    [xfm translateXBy:cp.x yBy:cp.y];
    [xfm rotateByRadians:angle];
    [xfm translateXBy:-cp.x yBy:-cp.y];
    
    return xfm;
    }
    

    【讨论】:

    • 教程链接已失效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多