【问题标题】:Different results of adding UIBezierPath in UIKit and SpriteKitUIKit和SpriteKit中添加UIBezierPath的不同结果
【发布时间】:2015-10-06 01:58:33
【问题描述】:

我正在尝试使用 SKShapeNode 将弧线添加到我的 SpriteKit 场景中。如果我用 UIView 画一条弧线,例如:

- (void)drawRect:(CGRect)rect {
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame)) radius:64.0f startAngle:0 endAngle:M_PI*4/3 clockwise:YES];
    [[UIColor greenColor] setStroke];
    path.lineWidth = 2.0f;
    [path stroke];
}

我得到以下信息:

我得到了我所期望的。如果我通过 SKScene 画出类似的弧线,例如:

- (void)createCircle {
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:128.0f startAngle:0 endAngle:M_PI*4/3 clockwise:YES];
    SKShapeNode *ring = [SKShapeNode shapeNodeWithPath:path.CGPath];
    ring.name = @"ring";
    ring.lineWidth = 20;
    ring.strokeColor = [SKColor magentaColor];
    ring.position = CGPointMake(CGRectGetMidX(self.view.bounds),CGRectGetMidY(self.view.bounds));
    [self.scene addChild:ring];
}

我得到以下图片。这不是我期望看到的。它是逆时针方向的。为什么我没有像第一张图片那样得到弧线?我需要翻转轴或其他东西吗?如果重要的话,我的开发目标是 iOS 8.4。

【问题讨论】:

    标签: ios objective-c sprite-kit uikit uibezierpath


    【解决方案1】:

    UIKit 和 SpriteKit 中的 2D 坐标系不同。

    要实现同样的圆弧,修改path

    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:128.0f startAngle:0 endAngle:-M_PI*4/3 clockwise:NO];
    

    【讨论】:

    • 我想我听说过。谢谢。
    猜你喜欢
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多