Ios UIScrollView autoresizemask不工作

Ios UIScrollView autoresizemask不工作,ios,objective-c,uiscrollview,Ios,Objective C,Uiscrollview,在下面显示的代码中,我创建了一个滚动视图,并在其中添加了一个图像视图。不幸的是,autoresizingmask不工作,图像显示在屏幕的一部分。代码如下所示: // Scroll View Setup self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 216, 300, 344)]; self.scrollView.autoresizingMask = (UIViewAutoresizingFlexibleW

在下面显示的代码中,我创建了一个滚动视图,并在其中添加了一个图像视图。不幸的是,autoresizingmask不工作,图像显示在屏幕的一部分。代码如下所示:

// Scroll View Setup
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 216, 300, 344)];
self.scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin);
self.scrollView.delegate = self;
self.scrollView.contentMode = UIViewContentModeScaleToFill;
self.scrollView.scrollEnabled=YES;
self.scrollView.userInteractionEnabled=YES;
self.scrollView.bounces = YES;
self.scrollView.bouncesZoom = YES;
self.scrollView.delaysContentTouches = YES;
self.scrollView.canCancelContentTouches = YES;
self.scrollView.minimumZoomScale = 1;
self.scrollView.maximumZoomScale = 10;
self.scrollView.zoomScale = 1;
self.scrollView.opaque = YES;
self.scrollView.clipsToBounds = YES;
self.scrollView.clearsContextBeforeDrawing = YES;
self.scrollView.contentSize = CGSizeMake(300, 344);
self.scrollView.autoresizesSubviews = YES;
[self.view addSubview:self.scrollView];

// Image View setup
self.pgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 344)];
self.pgImage.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin);
self.pgImage.contentMode = UIViewContentModeScaleAspectFit;
self.pgImage.opaque = YES;
self.pgImage.clipsToBounds = NO;
self.pgImage.clearsContextBeforeDrawing = YES;
self.pgImage.autoresizesSubviews = YES;

[self.scrollView addSubview:self.pgImage];

//autoresize scrollView
CGFloat scrollViewHeight = 0.0f;
CGFloat scrollViewWidth = 0.0f;
for (UIView *view in self.scrollView.subviews) {
    CGFloat height = (view.frame.size.height + view.frame.origin.y);
    scrollViewHeight = ((height > scrollViewHeight) ? height : scrollViewHeight);
    CGFloat width = (view.frame.size.width + view.frame.origin.x);
    scrollViewWidth = ((width > scrollViewWidth) ? width : scrollViewWidth);
}

[self.scrollView setContentSize:(CGSizeMake(scrollViewWidth, scrollViewHeight))];

对我来说还可以,但可能是缺少了什么。欢迎您的帮助。提前感谢您。

使用
autolayout
。在
ScrollView
中添加
UIView
,然后在其上添加您的
ImageView

在纵向模式下的UI(pgImage)例外情况。UI始终处于纵向模式。谢谢。它工作正常,但没有自动布局,只是遵循其余部分。这很酷。:)使用autolayout可以使这类内容更简单。。!