Ios 当用户更改为横向时,如何布局UIScrollView?

Ios 当用户更改为横向时,如何布局UIScrollView?,ios,objective-c,cocoa-touch,uiscrollview,Ios,Objective C,Cocoa Touch,Uiscrollview,我对景观适应很陌生。我的带有嵌入式UIImageView的UIScrollView在纵向效果上非常完美,但当我切换到横向时,它简直是一团糟 我尝试了以下方法: - (void)viewDidLayoutSubviews { self.scrollView.frame = self.view.frame; } 但这是徒劳的。当我旋转视图时,它仍然会将图像投射到左下角 如何布局UIScrollView,使其在切换到横向视图时保持居中?(我所追求的是与Photos.app几乎相同的行为。)

我对景观适应很陌生。我的带有嵌入式UIImageView的UIScrollView在纵向效果上非常完美,但当我切换到横向时,它简直是一团糟

我尝试了以下方法:

- (void)viewDidLayoutSubviews {
    self.scrollView.frame = self.view.frame;
}
但这是徒劳的。当我旋转视图时,它仍然会将图像投射到左下角

如何布局UIScrollView,使其在切换到横向视图时保持居中?(我所追求的是与Photos.app几乎相同的行为。)

在my
scrollViewDidZoom:
中,如果相关的话,我也有以下内容(当用户滚动时,它会使其居中):

CGRect newImageViewFrame=self.imageView.frame;
//水平居中
if(newImageViewFrame.size.width
您是否在使用AutoresizingMask?如果滚动视图是
self.view
的子视图,您可能打算使用
self.scrollView.frame=self.view.bounds(非
self.view.frame
CGRect newImageViewFrame = self.imageView.frame;

// Center horizontally
if (newImageViewFrame.size.width < CGRectGetWidth(scrollView.bounds)) {
    newImageViewFrame.origin.x = (CGRectGetWidth(scrollView.bounds) - CGRectGetWidth(self.imageView.frame)) / 2;
}
else {
    newImageViewFrame.origin.x = 0;
}

// Center vertically
if (newImageViewFrame.size.height < CGRectGetHeight(scrollView.bounds)) {
    newImageViewFrame.origin.y = (CGRectGetHeight(scrollView.bounds) - CGRectGetHeight(self.imageView.frame)) / 2;
}
else {
    newImageViewFrame.origin.y = 0;
}

self.imageView.frame = newImageViewFrame;