[英]CAShapeLayer is not drawn in simulator in iPad retina mode
I have a small piece of code, that draws a circle as CAShapeLayer: 我有一小段代码,它绘制一个圆圈作为CAShapeLayer:
- (void) viewWillAppear:(BOOL)animated {
CGFloat size = MIN(self.view.frame.size.width, self.view.frame.size.height);
CAShapeLayer *circleLayer = [CAShapeLayer layer];
circleLayer.fillColor = [[UIColor redColor] CGColor];
circleLayer.frame = CGRectMake((self.view.frame.size.width - size) / 2.0 ,(self.view.frame.size.height - size) / 2.0, size, size);
CGMutablePathRef pathRef = CGPathCreateMutable();
CGPathAddEllipseInRect(pathRef, NULL, CGRectMake(0, 0, size, size));
circleLayer.path = pathRef;
CGPathRelease(pathRef);
[self.view.layer addSublayer:circleLayer];
}
The circle is shown correctly on iPad 2 and in simulator in non-retina mode. 在iPad 2和非视网膜模式的模拟器中正确显示圆圈。 When I switch the simulator into retina mode, the circle is not shown at all.
当我将模拟器切换到视网膜模式时,根本不显示圆圈。 Unfortunately, I don't have an actual iPad 3 yet, so I cannot say, if it works on actual device.
不幸的是,我还没有真正的iPad 3,所以我不能说,如果它适用于实际的设备。 Can anyone exlain, what I am doing wrong?
任何人都可以解雇,我做错了什么?
Update: I reported this as a bug to Apple. 更新:我将此报告为Apple的错误。 They told me, that the bug is duplicate and the other bug was still open.
他们告诉我,这个bug是重复的,另一个bug仍然是开放的。 After a while it got closed, but after the last XCode update it is still reproducible
一段时间后它关闭了,但在最后一次XCode更新后,它仍然可以重现
Update 2: Checked it on a real iPad 3. Works correctly. 更新2:在真正的iPad上检查它3.正常工作。
Indeed! 确实! With your code, if
circleLayer
's size
is 512 or above, the circle won't display on the Simulator's retina iPad... 使用您的代码,如果
circleLayer
的size
为512或更高,则该模拟器的视网膜iPad上不会显示该圆圈...
Now, given that I want to be able to sleep peacefully tonight, here's a workaround that uses CALayer's cornerRadius
property to do the trick: 现在,鉴于我希望能够今晚安静地睡觉,这是一个使用CALayer的
cornerRadius
属性来解决这个问题的解决方法:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated]; //always call super
CGFloat size = MIN(self.view.frame.size.width, self.view.frame.size.height);
NSLog(@"size: %f", size);
CALayer *circleLayer = [CALayer layer];
[circleLayer setBackgroundColor:[UIColor redColor].CGColor];
circleLayer.frame = CGRectMake((self.view.frame.size.width - size) / 2.0 ,(self.view.frame.size.height - size) / 2.0, size, size);
circleLayer.cornerRadius = size/2;
[self.view.layer addSublayer:circleLayer];
}
This will display the same circle in the iPad retina Simulator too. 这也将在iPad视网膜模拟器中显示相同的圆圈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.