为什么此绘图代码在某些运行iOS 8.1的iPad上有效,而在其他iPad上无效



我遇到了一个奇怪的问题,我的代码适用于某些iPad型号,但不适用于其他型号,即使它们运行的是相同版本的iOS。 这个绘制白色圆圈的简单代码适用于运行iOS 8.1.1的iPad 4,但不适用于运行8.1.1的iPad Mini Retina。 这甚至可以在模拟器中重现。 它在"iPad Retina 8.1"或"iPad 2 8.1"模拟器上运行时有效, 但不是"iPad Air 8.1"。当它不起作用时,它不会画一个小的白色圆圈。视图为空白。为什么会这样?

@implementation MyUIViewSubclass
{
    CAShapeLayer* animationLayer;
    CGMutablePathRef smallCircle;
}
- (id) initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder])
    {
        smallCircle = CGPathCreateMutable();
        CGPathAddArc(smallCircle, NULL, self.bounds.size.width / 2, self.bounds.size.height / 2, 32, (CGFloat)M_PI, -(CGFloat)M_PI, NO);
        animationLayer = [CAShapeLayer layer];
        animationLayer.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
        animationLayer.lineWidth = 1;
        animationLayer.strokeColor = [[UIColor whiteColor] CGColor];
        animationLayer.fillColor = [[UIColor clearColor] CGColor];
        animationLayer.path = smallCircle;
        [self.layer addSublayer:animationLayer];
    }
    return self;
}
@end

我写问题时想通了这一点。 它在 64 位设备上不起作用。 当我将CGFloat更改为浮动时,它起作用了。CGFloat 在 32 位和 64 位平台上的定义不同。

相关内容

最新更新