2017-02-09 12 views
8

Mam do czynienia z dziwnym problemem z MKMapView. Użyłem MKOverlayRenderer. Teraz problem polega na tym, że powiększam obraz poprawnie. Ale w przypadku powiększenia część fragmentu obrazu jest obcięta. Wygląda na to, że część nakładki MapView znajduje się powyżej nakładki. Poniżej znajduje się mój kod renderera nakładki.Nakładka MapView jest odcięta po powiększeniu

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) 
    } 
} 

Choć nie wiem rzeczywistą przyczynę, ale kiedy jestem komentując ctx.rotate(by:) funkcję problem ten został rozwiązany. Ale to nie jest moje rozwiązanie, ponieważ obraz musi być na miejscu.

zoom out zoom in

+0

Czy próbowałeś wstawić swój kod powiększania do kolejki wysyłkowej? –

+0

nie działa !!!!! –

+0

Nadal walczę ... Czy ktoś może mi pomóc? –

Odpowiedz

-1

Proszę Spróbuj poniżej.

override func draw(_ mapRect: MKMapRect, zoomScale: MKZoomScale, 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, blendMode: CGBlendMode.normal, alpha: 1.0) 
     UIGraphicsPopContext(); 
} 
    } 
+0

nie działa !!!!! –

Powiązane problemy