swift3 – 放大后MapView叠加层正在切断
发布时间:2020-12-14 05:29:56 所属栏目:百科 来源:网络整理
导读:我正面临一个MKMapView的奇怪问题.我使用过MKOverlayRenderer.现在的问题是当我缩小图像显示正确时.但是在放大的情况下,图像的某些部分会被切断.看起来MapView的一部分正在叠加层之上.以下是我的叠加渲染器代码. class MapOverlayRenderer: MKOverlayRendere
我正面临一个MKMapView的奇怪问题.我使用过MKOverlayRenderer.现在的问题是当我缩小图像显示正确时.但是在放大的情况下,图像的某些部分会被切断.看起来MapView的一部分正在叠加层之上.以下是我的叠加渲染器代码.
class MapOverlayRenderer: MKOverlayRenderer { var overlayImage: UIImage var plan: Plan init(overlay: MKOverlay,overlayImage: UIImage,plan: Plan) { self.overlayImage = overlayImage self.plan = plan super.init(overlay: overlay) } override func draw(_ mapRect: MKMapRect,zoomScale: MKZoomScale,in ctx: CGContext) { let theMapRect = overlay.boundingMapRect let theRect = rect(for: theMapRect) // Rotate around top left corner ctx.rotate(by: CGFloat(degreesToRadians(plan.bearing))); // Draw the image UIGraphicsPushContext(ctx) overlayImage.draw(in: theRect,blendMode: CGBlendMode.normal,alpha: 1.0) UIGraphicsPopContext(); } func degreesToRadians(_ x:Double) -> Double { return (M_PI * x / 180.0) } } 虽然我不知道实际的原因,但是当我评论ctx.rotate(by :)函数时,这个问题已得到修复.但这不是我的解决方案,因为图像必须处于适当位置.
请尝试以下.
override func draw(_ mapRect: MKMapRect,in ctx: CGContext) { DispatchQueue.main.async { let theMapRect = overlay.boundingMapRect let theRect = rect(for: theMapRect) // Rotate around top left corner ctx.rotate(by: CGFloat(degreesToRadians(plan.bearing))); // Draw the image UIGraphicsPushContext(ctx) overlayImage.draw(in: theRect,alpha: 1.0) UIGraphicsPopContext(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |