dimanche 26 juin 2016
ScrollView zoom leaving top, bottom margin
I have a scrollview with a nested image view, when I zoom the image enlarges as it should. However, if I scroll down the image I can go past the bottom of the image even though I have set the scrollview content size to the size of the new zoomed image.
What I ideally would like to happen is when I scroll to the bottom of the image is to have the scroll view stop and not allow me to scroll any further. Similarly when I scroll left or right I don't want there to be any obvious margin appearing.
Would be grateful for any help.
class ViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.scrollView.minimumZoomScale = 1;
self.scrollView.maximumZoomScale = 2;
self.imageView.contentMode = UIViewContentMode.ScaleAspectFit;
self.imageView.image = UIImage(named:"cecil.jpg" )
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView?
{
self.scrollView.contentSize = self.imageView.frame.size
self.scrollView.contentInset = UIEdgeInsetsZero;
return self.imageView;
}
}
I turned off bouncing in the properties - the image displays stops the scrolling when it reaches either side, but not from top to bottom which still shows a margin. When the device is in horizontal then the issue manifests from left to right.
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire