This repository was archived by the owner on May 28, 2025. It is now read-only.
CGContextSetShadow does not work with transparency layers #584
Copy link
Copy link
Closed
Description
Issue Description
Trying to use CGContextSetShadow with CGContext(Begin/End)TransparencyLayer does not result in a shadow.
Reproduction Steps
- Enable shadows with CGContextSetShadow
- Begin a transparency layer
- Draw several shapes
- End the transparency layer
Expected Behavior
The shapes drawn in the transparency layer should have a unified shadow, as if the shapes were one whole shape with a shadow.
Observed Behavior
No shadow is drawn at all.
Pull Request, Test Case, or Sample Code
See this URL for how Apple expects it to work.
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat maxWidth = rect.size.width;
CGFloat maxHeight = rect.size.height;
// White background
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillRect(context, CGRectMake(0, 0, maxWidth, maxHeight));
// Rect Size
CGFloat rectWidth = maxWidth / 2.0;
CGFloat rectHeight = rectWidth;
// Enable shadow
CGSize shadowOffset = CGSizeMake(10, 20);
CGContextSetShadow(context, shadowOffset, 10);
// Begin Transparency
CGContextBeginTransparencyLayer(context, NULL);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextFillRect(context, CGRectMake(rectWidth / 2 + 25, maxHeight / 2 - rectHeight / 2 - 50, rectWidth, rectHeight));
CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor);
CGContextFillRect(context, CGRectMake(rectWidth / 2 - 25, maxHeight / 2 - rectHeight / 2 + 25, rectWidth, rectHeight));
CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);
CGContextFillRect(context, CGRectMake(rectWidth / 2 - 50, maxHeight / 2 - rectHeight / 2, rectWidth, rectHeight));
// End Transparency
CGContextEndTransparencyLayer(context);
Activity
rajsesh commentedon Jun 28, 2016
Fixed through #576.
adein commentedon Jun 28, 2016
@rajsesh-msft #576 added the transparency APIs; it did not fix the issue with CGContextSetShadow. CGContextSetShadow doesn't seem to work at all with drawing shapes, with or without using the transparency APIs.
rajsesh commentedon Jun 28, 2016
Aaron (@adein) thanks for the clarification.
3 remaining items
rajsesh commentedon Oct 1, 2016
Will do this in D2D as part of the CG D2d migration effort.
rajsesh commentedon Nov 2, 2016
Dustin L. Howett (MSFT) (@DHowett-MSFT) this is probably already addressed in the CGD2D branch?
DHowett-MSFT commentedon Nov 2, 2016
This will be covered. Thanks!
rajsesh commentedon Nov 18, 2016
Will validate this with #1417
[CGD2D] Add support for Transparency Layers. (#1496)
[CGD2D] Add support for Transparency Layers. (#1496)
Release 1702.1 (#1992)