I have build an uiscrollview with pure autolayout, so I don't use :
[scrollView setContentSize:CGMakeSize(contentWidth,contentHeight)];
the problem is that now I need to get the contentSize.height of the uiScrollView, but with autoloayout I am getting 0.
I need to get the contentSize.height to zoom in the scrollView when the user double tap.
the code I want to use is this one : ZoomToPoint
Can you help me to use this code with autoLayout?
Thanks a lot
I don't have enough information to have any clue why you're getting 0, that doesn't seem to be happening to either of the scroll views in the app I'm currently working on. Maybe your autolayout constraints aren't quite right? Autolayout + UIScrollView
s aren't a very simple combination. I've found it easiest to place all views with a plain UIView
"container," and place that within a scroll view.
But do you actually even need the contentSize.height? To me, it makes sense to just double the scale on a zoomed-out double tap and zoom back out to 100% on a zoomed-in double tap:
func doubleTapReceived(recognizer: UITapGestureRecognizer) {
if recognizer.state == .Ended {
if photo.scrollView.zoomScale == 1.0 {
let point = recognizer.locationOfTouch(0, inView: <one of your views>)
<your scroll view>.zoomToPoint(point, withScale: 2.0, animated: true)
} else {
<your scroll view>.zoomToRect(photo.frame, animated: true)
}
}
}
No subclassing required.
Here's the analogous part of my code. Maybe try cloning my project and building it and seeing how it differs from what you have? You can get to that particular scroll view by going to the Photos tab and tapping one of the thumbnail images in the collection view.