简体   繁体   English

为什么我的Arcs不在64位iOS设备上绘图?

[英]Why aren't my Arcs drawing on 64 bit iOS devices?

I have code that uses the Core Foundation function CGPathAddArc() to create arcs (aka semicircles). 我有使用Core Foundation函数CGPathAddArc()创建圆弧(也称为半圆)的代码。 In some cases the arcs don't draw when the code is run on 64 bit OS devices (iPad Air and Air 2, iPhone 5s, iPhone 6, etc), but they do draw on 32 bit devices. 在某些情况下,当代码在64位OS设备(iPad Air和Air 2,iPhone 5s,iPhone 6等)上运行时,不会绘制圆弧,但会在32位设备上绘制。

The code looks something like this: 代码看起来像这样:

CGPathAddArc(path,
             nil,
             CGRectGetMidX(bounds),
             CGRectGetMidY(bounds),
             MIN(bounds.size.width/2, bounds.size.height/2),
             3*M_PI_2,
             -M_PI_2,
             _drawArcClockwise
             );

In that example, the arc draws if _drawArcClockwise is TRUE, but doesn't draw anything if _drawArcClockwise is FALSE . 在该示例中,如果_drawArcClockwise为TRUE,则绘制弧线,但是如果_drawArcClockwiseFALSE ,则不绘制_drawArcClockwise

I've also tested the equivalent UIBezierPath function, and it gives the same results. 我还测试了等效的UIBezierPath函数,它给出了相同的结果。

You can see an example project that shows this problem on github in the repo called ArcTest (link) 您可以在名为ArcTest的存储库中的github上看到一个显示此问题的示例项目(链接)

The answer seems to be that there is a bug in the 64 bit implementation of iOS. 答案似乎是iOS的64位实现中存在错误。 (Or perhaps the bug is in the 32 bit implementation.) Regardless of which is the correct behavior, 32 bit and 64 bit devices behave differently in response to the same call with the same parameters. (或者可能是32位实现中的错误。)无论哪种行为正确,32位和64位设备在响应具有相同参数的同一调用时的行为都会有所不同。

The fix to the code above is to swap the startAngle and endAngle parameters when clockwise == FALSE: 修复上面的代码是在顺时针== FALSE时交换startAngle和endAngle参数:

CGFloat startAngle, endAngle;
startAngle = _drawArcClockwise ? 3*M_PI_2 : -M_PI_2;
endAngle =   _drawArcClockwise ? -M_PI_2  : 3*M_PI_2;
CGPathAddArc(path,
             nil,
             CGRectGetMidX(bounds),
             CGRectGetMidY(bounds),
             MIN(bounds.size.width/2, bounds.size.height/2),
             startAngle,
             endAngle,
             _drawArcClockwise
             );

That code works on both 32 and 64 bit platforms. 该代码可在32位和64位平台上运行。 I haven't checked to see the direction the arc is drawn on both platforms though. 我还没有检查在两个平台上绘制圆弧的方向。 (Normally that doesn't matter but it would matter if you were creating an animation using the arc in a shape layer and manipulating the strokeStart and/or strokeEnd properties of the shape layer.) (通常没关系,但是如果您是在形状层中使用圆弧创建动画并操纵形状层的strokeStart和/或strokeEnd属性,那将很重要。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM