3

I have a custom MKOverlay and MKOverlayView. When the MKOverlayView is created, I can set the alpha of the view:

-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
    DatasetOverlay *datasetOverlay = (DatasetOverlay *)self.overlay;

    UIImage *image = [UIImage imageWithData:datasetOverlay.imageData];

    CGImageRef imageReference = image.CGImage;

    MKMapRect theMapRect = [self.overlay boundingMapRect];
    CGRect theRect = [self rectForMapRect:theMapRect];

    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextTranslateCTM(context, 0.0, -theRect.size.height);
    CGContextSetAlpha(context, 1);
    CGContextDrawImage(context, theRect, imageReference);
}

But I want to be able to change the alpha of the view after its draw.

How can I do that?

I am have not worked much with Core Graphics yet.

Padin215
  • 7,444
  • 13
  • 65
  • 103

1 Answers1

0
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
    DLog(@"Fired");
    DatasetOverlay *datasetOverlay = (DatasetOverlay *)self.overlay;

    UIImage *image = [UIImage imageWithData:datasetOverlay.imageData];

    CGImageRef imageReference = image.CGImage;

    MKMapRect theMapRect = [self.overlay boundingMapRect];
    CGRect theRect = [self rectForMapRect:theMapRect];



    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextTranslateCTM(context, 0.0, -theRect.size.height);
//    CGContextSetAlpha(context, 1);
    CGContextDrawImage(context, theRect, imageReference);
}

K, thanks to @ttarules's comment, I did some testing and realized I needed to remove the CGContextSetAlpha() and just set the alpha with the MKOverlayView's alpha property. I can now change the alpha outside of initialization and give me what I need.

Padin215
  • 7,444
  • 13
  • 65
  • 103