Note that there are some explanatory texts on larger screens.

plurals
  1. POBug in CALayer's shadowPath?
    primarykey
    data
    text
    <p>I'm trying to draw a custom-shaped shadow using <code>CALayer</code>:</p> <pre><code>#import &lt;QuartzCore/QuartzCore.h&gt; @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's 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 </code></pre> <p>You can create an empty Cocoa project in Xcode, replace your app.delegate's .m file content with the above code and try it yourself.</p> <p>It looks like specific shadow path geometry causes <code>CALayer</code> to go nuts.</p> <p>For example:</p> <pre><code>CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 100, 48)); CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48)); </code></pre> <p>This one looks perfectly okay:</p> <p><img src="https://i.stack.imgur.com/I1HQa.png" alt="Okay case"></p> <p>Now I'm going to make the 1st rectangle wider by 20 points:</p> <pre><code>CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 120, 48)); CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48)); </code></pre> <p><img src="https://i.stack.imgur.com/qWrXD.png" alt="Whoa case"></p> <p>...doesn't look so good anymore. Plus 10 points:</p> <pre><code>CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 130, 48)); CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48)); </code></pre> <p><img src="https://i.stack.imgur.com/y0iur.png" alt="WTF case"></p> <p>Now that is plain wrong, isn't it?</p> <p>So, the question is: what the hell is going on, am I doing it wrong or something? Do you think it's a bug and I should file a report? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload