mat*_*mer 5 macos cocoa core-graphics ios
我有两段代码,其中一段完美无缺(iOS版本),另一段无法正常运行(Mac版本).我无法解决使用NSBezierPath而不是UIBezierPath的Mac版本的问题.
iOS版本
我有一段代码完全按照我在iOS上使用UIBezierPath的方式工作.这是代码:
let center = CGPoint(x: size.width / 2.0, y: size.height / 2.0)
let radius = size.width / 2.0
let startAngle = angle
let endAngle = 180.0 - startAngle
let bezierPath = UIBezierPath()
bezierPath.addArcWithCenter(center, radius: radius, startAngle: startAngle.radians, endAngle: endAngle.radians, clockwise: true)
println(bezierPath)
return bezierPath
Run Code Online (Sandbox Code Playgroud)
它产生以下输出
<UIBezierPath: 0x7fe348f82910; <MoveTo {42.677669529663689, 42.677669529663689}>,
<CurveTo {7.3223304703363148, 42.677669529663689} {32.914562235881945, 52.440776823445439} {17.085437764118062, 52.440776823445432}>
Run Code Online (Sandbox Code Playgroud)
并显示以下图像

Mac OS X版
这正是我想要的,除了它是iOS.我想将此代码翻译为OS X/Cocoa.这就是我想出来的
let center = CGPoint(x: size.width / 2.0, y: size.height / 2.0)
let radius = size.width / 2.0
let startAngle = angle
let endAngle = 180.0 - startAngle
let bezierPath = NSBezierPath()
bezierPath.appendBezierPathWithArcWithCenter(center, radius: radius, startAngle: startAngle.radians, endAngle: endAngle.radians, clockwise: true)
println(bezierPath)
return bezierPath
Run Code Online (Sandbox Code Playgroud)
(它与iOS代码几乎完全相同).
这里的输出是
Path <0x600000122800>
Bounds: {{-4.9018102839097546e-05, -4.9018102839077596e-05}, {50.000098036205685, 50.000094758067902}}
Control point bounds: {{-0.18691031775632938, -0.18691031775632855}, {50.373820635512658, 50.37016203886877}}
49.997651 25.342684 moveto
50.186910 11.536862 39.148505 0.191608 25.342684 0.002349 curveto
11.536862 -0.186910 0.191608 10.851495 0.002349 24.657316 curveto
-0.186910 38.463138 10.851495 49.808392 24.657316 49.997651 curveto
38.196255 50.183252 49.422202 39.556558 49.978864 26.027794 curveto
Run Code Online (Sandbox Code Playgroud)
产生以下形状

两个代码段都给出了相同的输入并使用相同的方法来计算弧度等.据我所知,除了输出之外,两者之间的一切都是相同的.值得注意的是,我将每个路径转换为UIImages和NSImages后绘制它们.如果我发布我正在使用的代码,请告诉我.
我也尝试过moveToPoint将两段代码都放到正确的起始位置(在iOS上不必要,但没有解决OS X上的问题).
非常感谢您的帮助.
原来,在iOS上addArcWithCenter采用弧度startAngle和endAngle,以及OS X appendBezierPathWithArcWithCenter花费度.