Ios UIImageView未在superview中按预期对齐

Ios UIImageView未在superview中按预期对齐,ios,objective-c,uiscrollview,uiimageview,Ios,Objective C,Uiscrollview,Uiimageview,我正在水平滚动显示图像,并且在自定义UIView中有一个UIScrollView。Scrollview与自定义视图的高度相同,但宽度不同。在设置图像时,我正在for循环中创建UIImageView。一切都很好,除了加载,UIImageView显示的Y轴比它应该显示的更远,我不知道为什么。这是密码 - (void)createImageViewer { NSLog(@"Entered createImageViewer"); // size attributes of the main view

我正在水平滚动显示图像,并且在自定义UIView中有一个UIScrollView。Scrollview与自定义视图的高度相同,但宽度不同。在设置图像时,我正在for循环中创建UIImageView。一切都很好,除了加载,UIImageView显示的Y轴比它应该显示的更远,我不知道为什么。这是密码

- (void)createImageViewer {

NSLog(@"Entered createImageViewer");
// size attributes of the main view and scroll view
CGFloat mainViewHeight = self.mainView.frame.size.height; // height of the main view
CGFloat mainViewWidth = self.mainView.frame.size.width; // width of the the main view
CGFloat scrollViewHeight = self.scrollView.frame.size.height; // height of the scroll view
CGFloat scrollViewWidth = self.scrollView.frame.size.width; // width of the scroll view

self.arrayOfImages = [self loadImages];
self.scrollView.pagingEnabled = YES;

[self.mainView addSubview:self.scrollView];

for (int i = 0; i < [self.arrayOfImages count]; i++){
    UIImage *image = self.arrayOfImages[i];//Gets the image at the index i
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    //Shift each image over by the scrollView's width starting the first image at 0
    imageView.frame = CGRectMake(scrollViewWidth * i, 0, scrollViewWidth, scrollViewHeight);

    [self.scrollView addSubview:imageView];
}

int numberOfImages = [self.arrayOfImages count];

self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * numberOfImages, self.scrollView.frame.size.height);
}


我不允许发布图像,但基本上,图像垂直放置在我认为应该放置的位置,大约50个点,这与superview是一致的。我之所以期望这样,是因为scrollview是在情节提要中创建的,并且在superview高度相同的情况下均匀放置,但宽度不一样。提前谢谢

你在一个UINavigationController里面吗?检查序列图像板上名为“调整滚动视图插入”的属性。或者检查整个插图主题。我不是ScrollView的大用户,但我听起来像是这样。你使用哪种contentMode?contentMode是按比例填充的。播放了不同的内容模式,但没有修复垂直对齐。我找不到调整滚动视图插图,但我在storyboard inspector中看到了内容插图,但它们都设置为0,并且调整它们完全没有任何作用。是否图像视图的位置正确,但是scrollView本身有一个frame.origin.y大于零?