Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

CGContextSetShadow does not work with transparency layers #584

Closed

Description

@adein

Issue Description

Trying to use CGContextSetShadow with CGContext(Begin/End)TransparencyLayer does not result in a shadow.

Reproduction Steps
  1. Enable shadows with CGContextSetShadow
  2. Begin a transparency layer
  3. Draw several shapes
  4. 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

  1. rajsesh commented on Jun 28, 2016

    @rajsesh
    Contributor

    Fixed through #576.

  2. adein commented on Jun 28, 2016

    @adein
    CollaboratorAuthor

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

  3. rajsesh commented on Jun 28, 2016

    @rajsesh
    Contributor

    Aaron (@adein) thanks for the clarification.

  4. 3 remaining items

  5. rajsesh commented on Oct 1, 2016

    @rajsesh
    Contributor

    Will do this in D2D as part of the CG D2d migration effort.

  6. rajsesh commented on Nov 2, 2016

    @rajsesh
    Contributor

    Dustin L. Howett (MSFT) (@DHowett-MSFT) this is probably already addressed in the CGD2D branch?

  7. DHowett-MSFT commented on Nov 2, 2016

    @DHowett-MSFT

    This will be covered. Thanks!

  8. rajsesh commented on Nov 18, 2016

    @rajsesh
    Contributor

    Will validate this with #1417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions