I have an image drawn using PaintCode. And that image has a Scale variable. on line marked "// A", I've edited the usual PaintCode generated code so that I can pass in a scale and have the image created at the correct height and width.
public class func imageOfMap(scale scale: CGFloat = 1) -> UIImage {
UIGraphicsBeginImageContextWithOptions(
CGSizeMake(scale*1660, scale*1832), // A
false, 0)
MapStyleKit.drawMap(scale: scale)
let imageOfMap = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return imageOfMap
}
Now I have a UIImageView inside of a UIScrollView. And I have the scrollview contrained to the inside of my ViewController's view, and the imageview constrained to the inside of the scrollview, using autolayout constraints.
I've looked into "viewForZooming" and "scrollViewDidZoom", but those only use a CGAffineTransformScale on the image view. I've tried setting the correct image in "scrollviewDidZoom" and I've tried using my own pinch gesture recognizers, but my math must be wrong about some where but I don't know where.
Each time I zoom, I want to supply a new image the image view from PaintCode at the correct zoom level.
Further, I want the image to "stay in place" as one would expect when pinching to zoom in Google Maps or Apple Maps. Right now I'm trying to multiply the scrollView's contentOffset by a factor of the contentSize, the scrollView's frame and the current scale, and the image is jumping around alot when zooming.
I've done a lot of researching and tinkering and haven't been able to figure this out. So I'm finally asking here. Please help! Thank you for your time.