Image with zoom option or image-based map view

Asked

Viewed 53 times

1

I’m developing an application where I need to insert a map of an internal location (so apple’s map view has not registered ) I wonder if it has how to mount a mapView (mounting the internal location ) or if I do not have if I can insert an Imgview and allow zooming , because I have the plant in jpg ? Thank you

Current code :

class MapasViewController: UIViewController, UIScrollViewDelegate {

@IBOutlet weak var imgMapa: UIImageView! // *** Declara imgView
@IBOutlet weak var scrollView: UIScrollView!
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
    return imgMapa
}

override func viewDidLoad() {
    super.viewDidLoad()
    print("*** LOG : TELA DE MAPAS CARREGADA ***")


    let width: CGFloat = imgMapa.image!.size.width
    let height: CGFloat = imgMapa.image!.size.height

    scrollView.minimumZoomScale = 1.0
    scrollView.maximumZoomScale = 6.0
    scrollView.contentSize = CGSizeMake(width, height)
    scrollView.delegate = self
    scrollView.zoomScale = 1.0

}




}

1 answer

1


My answer goes to the second option, because I don’t know if with the MKMapKit you can do this.

What you need, basically, is to put a UIImageView in a UIScrollView. If using the Builder interface and auto layout, add the following elements:

UIScrollView
|_ UIView
   |_ UIImageView

And with them, their respective constraints to obey any screen size.

And in the UIViewController, the delegate and the related properties:

class MapaViewController: UIViewController, UIScrollViewDelegate {
    @IBOutlet weak var imgMapa: UIImageView!
    @IBOutlet weak var scrollView: UIScrollView!
}

What will set this image to zoom in is delegate of UIScrollView:

func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
    return imgMapa
}

And finally, when loading the screen, set the properties of UIScrollView:

let width: CGFloat = imgMapa.image!.size.width
let height: CGFloat = imgMapa.image!.size.height

scrollView.minimumZoomScale = 1.0
scrollView.maximumZoomScale = 6.0
scrollView.contentSize = CGSizeMake(width, height)
scrollView.delegate = self
scrollView.zoomScale = 1.0

With this, you will be able to perform the gestures to zoom in on the image.

  • Friend I realized what you said... If you do not set the image it closes the app, if I set the image does not appear, it turns white, I put the settings you mentioned in the didload, right? you know how I can fix ?

  • added the code for better understanding

  • Try putting in the viewDidAppear. The image needs to be set, otherwise the moment you get imgMapa.image, will come back void.

  • Friend solved, had forgotten to put the view inside the Uiview, thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.