CAShapeLayer not drawn in iPad retina simulator

I have a small piece of code that draws a circle as a 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 displays correctly on the iPad 2 and in the simulator in non-retina mode. When I switch the simulator to retina mode, the circle does not appear at all. Unfortunately, I don’t have an iPad 3 right now, so I can’t say if it works on the device itself. Can someone post what I'm doing wrong?

Update: I reported this as an error for Apple. They told me that the error is duplicated and the other error is still open. After a while, it closed, but after the last Xcode update, it still plays.

Update 2: tested on a real iPad 3. Works correctly.

+4
source share
1 answer

Really! With your code, if circleLayer size is 512 or higher, the circle will not be displayed on the iPad retina simulator ...

Now, given that I want to sleep soundly today, here is a workaround that uses the CALayer cornerRadius property to do the trick:

 -(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.

0
source

Source: https://habr.com/ru/post/1415376/


All Articles