我遇到了一个奇怪的问题,即我的代码适用于某些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
答案 0 :(得分:1)
在我写这个问题时想出来了。它不适用于64位设备。当我将CGFloat改为浮动时,它起作用了。 CGFloat在32位与64位平台上的定义不同。