swift3 – 放大后MapView叠加层正在切断

swift3 – 放大后MapView叠加层正在切断,第1张

概述我正面临一个MKMapView的奇怪问题.我使用过MKOverlayRenderer.现在的问题是当我缩小图像显示正确时.但是在放大的情况下,图像的某些部分会被切断.看起来MapView的一部分正在叠加层之上.以下是我的叠加渲染器代码. class MapOverlayRenderer: MKOverlayRenderer { var overlayImage: UIImage v 我正面临一个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();}    }
总结

以上是内存溢出为你收集整理的swift3 – 放大后MapView叠加层正在切断全部内容,希望文章能够帮你解决swift3 – 放大后MapView叠加层正在切断所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1034731.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存