Search code examples
iosswiftuiscrollviewmobile-applicationswift2

How can I disable only Zoom out functionality in a scrol lview in Swift 2.3?


I am using pinch zoom for the image I have placed over the scroll view. I want to disable the only zoom out functionality and keep the zoom-in functionality. I have used this code but it is not working.

scrollView.frame = CGRectMake(0,0,sampleView.bounds.size.width,sampleView.bounds.size.height)
scrollView.delegate = self
scrollView.bounces = false
scrollView.alwaysBounceVertical = false
scrollView.alwaysBounceHorizontal = true
scrollView.contentSize = screenshot.size


scrollView.maximumZoomScale = 5.0
scrollView.minimumZoomScale = 1.0

imageView = UIImageView(image: screenshot)
imageView.frame = CGRectMake(0,0,sampleView.bounds.size.width,sampleView.bounds.size.height)
imageView.clipsToBounds = false

Solution

  • And, finally found the solution after a great struggle :

    scrollView.bounces = false
    scrollView.bouncesZoom = false
    scrollView.maximumZoomScale = 5.0
    

    We can disable zoom-out functionality and can have zoom-in functionality by setting the bounces and bouncesZoom properties to false. We can set MaximumZoomScale property to whatever value we want.