gpt4 book ai didi

ios - MKOverlayView 和改变它的 alpha

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:42:28 27 4
gpt4 key购买 nike

我有一个自定义的 MKOverlayMKOverlayView。创建 MKOverlayView 后,我可以设置 View 的 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);
}

但我希望能够在绘制后更改 View 的 alpha

我该怎么做?

我还没有使用 Core Graphics。

最佳答案

-(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 并提供我需要的内容。

关于ios - MKOverlayView 和改变它的 alpha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16342506/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com