我在UIViewController中有一个UIScrollView . 它启用了滚动和缩放功能 . 它包含一个UIImageView,当用户旋转设备时,想法是图像保持居中 . 问题是,当设备旋转时,它实际上显示在左侧而不是中心,它应该停留在那里 . 这是我正在使用的代码 . 当UIScrollView旋转时调用设置框架:
-(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);
}
3 回答
我在uiscrollview的子类中使用以下layoutsubviews方法:
您可能还需要设置滚动视图的
contentOffset
属性如果scrollview通过方向更改调整大小,请尝试此操作