我遇到了一个奇怪的问题,我的代码可以在某些 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”上运行。当它不起作用时,它不会绘制一个白色的小圆圈。 View 是空白的。为什么会发生这种情况?
@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 更改为 float 时,它起作用了。 CGFloat 在 32 位和 64 位平台上的定义不同。
关于ios - 为什么此绘图代码在某些运行 iOS 8.1 的 iPad 上有效,而在其他 iPad 上无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27285135/