UIScrollView odd behavior: zoom in, pan, zoom out leaves content view uncentered?

I saw same on my UIImageView with pinch in and out, in IB I checked on "Clip subviews" and the Image view started behaving better.

Up vote 4 down vote favorite 1 share g+ share fb share tw.

I have a custom UIViewController subclass controlling a UISCrollView containing an UIImageView, set up like so: UIViewController + UIScrollView (delegate: UIViewController, viewForZoomingInView: UIImageView) + UIImageView I can use the UIScrollView to zoom in on my image, and pan around -- but if I do so such that the center of the view is not the center of the image, and then zoom out fully, my image is off center; what's more, since I am at the minimum zoom scale at that point, I cannot pan around to re-center my image. My expectation was that when zooming out, UIScrollView would re-center the contentSize's area under its bounds so that you never see beyond the edge of the content view (or rather, the content view's size plus contentInset). Am I wrong in this assumption?

If so, what should I do to provide this behavior? Here's my code: - (void)viewDidLoad { super viewDidLoad; imageView. Image = image; imageView sizeToFit; float minimumScale = imageScrollView frame.size.

Width / imageView frame.size. Width; imageScrollView. ContentSize = imageView frame.

Size; imageScrollView. MaximumZoomScale = 2.0; imageScrollView. MinimumZoomScale = minimumScale; imageScrollView.

ZoomScale = imageScrollView. MinimumZoomScale; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return imageView; } - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale { // nothing } EDIT: Solution! You have to set clipsToBounds = YES on the UIScrollView to get the desired behavior.

I didn't find this initially because it is a property of UIView, not of UIScrollView directly. Iphone uiscrollview link|improve this question edited Feb 5 '10 at 19:02 asked Feb 5 '10 at 18:13dcrosta6,3801823 88% accept rate.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions