Ios MKOverlayView并更改其alpha
我有一个自定义的Ios MKOverlayView并更改其alpha,ios,objective-c,mkmapview,mkoverlay,Ios,Objective C,Mkmapview,Mkoverlay,我有一个自定义的MKOverlay和MKOverlayView。创建MKOverlayView时,我可以设置视图的alpha: -(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { DatasetOverlay *datasetOverlay = (DatasetOverlay *)self.overlay; UIImage
MKOverlay
和MKOverlayView
。创建MKOverlayView
时,我可以设置视图的alpha
:
-(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);
}
但我希望能够在绘制视图后更改视图的alpha
我该怎么做
很抱歉,我还没有对核心图形做过很多工作
-(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、 多亏@ttarules的评论,我做了一些测试,并意识到我需要删除
CGContextSetAlpha()
,只需使用MKOverlayView
的alpha属性设置alpha
。现在,我可以在初始化之外更改alpha
,并提供我需要的信息。您是否对MKOverlay进行子类化?如果是,那么[self-setAlpha:.7]如何;MKOverlay没有alpha属性,但MKOverlayView有。哇,是的,我是说MKOverlayView..我的宝贝,它让我走上了正确的轨道。