I have a UIScrollView inside a UIViewController. It has scrolling and zooming enabled. It contains a UIImageView and when the user rotates the device, the idea is that the image stays centered. The problem is, when the device is rotated, it actually appears off to the left instead of center, where it should be staying. Here is the code I’m using. Set frame is called when the UIScrollView rotates:
-(void)setFrame:(CGRect)frame {
float previousWidth = self.frame.size.width;
float newWidth = frame.size.width;
[super setFrame:frame];
self.imageView.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
[self setupScales];
self.zoomScale = self.zoomScale * (newWidth / previousWidth);
}
I use the following layoutsubviews method in my subclass of uiscrollview: