Error in CALayer shadowPath?

I am trying to draw a shadow on a form using CALayer :

 #import <QuartzCore/QuartzCore.h> @implementation ZKSBAppDelegate @synthesize window = _window; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSView *view = self.window.contentView; view.wantsLayer = YES; CALayer *shadowLayer = [CALayer layer]; shadowLayer.shadowOpacity = 1; shadowLayer.shadowRadius = 1; shadowLayer.shadowOffset = NSMakeSize(0, 0); CGMutablePathRef shadowPath = CGPathCreateMutable(); // setting the following rect width to 100 fixes everything. // setting it to 130 screws the shadow even more. CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 120, 48)); CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48)); shadowLayer.shadowPath = shadowPath; CGPathRelease(shadowPath); [view.layer addSublayer:shadowLayer]; } @end 

You can create an empty Cocoa project in Xcode, replace the contents of your app.delegate.m file with the above code, and try it yourself.

It seems that the specific geometry of the shadow path causes CALayer go nuts.

For instance:

 CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 100, 48)); CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48)); 

This looks completely normal:

Okay case

Now I'm going to make the first rectangle wider by 20 points:

 CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 120, 48)); CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48)); 

Whoa case

... no longer looks so good. Plus 10 points:

 CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 130, 48)); CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48)); 

Wtf case

Now this is wrong, isn't it?

So the question is: what the hell is going on, am I doing it wrong or something like that? You think this is a mistake, and I have to file a report?

+6
source share
1 answer

Yes, that sounds like a mistake. Even if it is not, by submitting a bug report, Apple should respond and provide you with useful information.

+3
source

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


All Articles