容器视图和滚动视图呈现偏移的表示形式

问题描述:

我有一个包含所有UI元素的UIScrollView的应用程序。容器中的一个元素,它具有一个嵌入UIViewController的UIScrollView,其中包含UIImage和一些UILabels。容器视图和滚动视图呈现偏移的表示形式

然而,我在容器的UIScrollView中呈现的问题与UIImage一样,它应该是填充整个可滚动内容,但顶部有一个栏。这个偏移很烦人,但也抛出了我对积分的计算。 (图像应该填充整个圆边界。

enter image description here

我设置的大小(使用约束)在含UIViewController中的viewDidLoad中(并且结果,盒子,容器视图的,是作为预期):

[self floorPlanContainerWidthConstraint].constant = [self view].frame.size.width - self.marginWidthConstraint.constant * 2; 
if([delegate isiPad]){ 
    [self floorPlanContainerHeightConstraint].constant = 300; 
} 
[_floorPlanContainer layoutIfNeeded]; 

然后在容器的UIViewController中,上ViewWillDisplay,我更新其包含与距离滚动视图的边缘处的尺寸的UIImageView“0”:

[super viewWillAppear:animated]; 

[self imageContainerHeightConstraint].constant = [self parentView].frame.size.height; 
[self imageContainerWidthConstraint].constant = [self parentView].frame.size.width; 

[_imageView layoutIfNeeded]; 
[_scrollView layoutIfNeeded]; 

NSLog(@"Parent frame: %f, %f, location %f, %f", [self parentView].frame.size.width, [self parentView].frame.size.height, [self parentView].frame.origin.x, [self parentView].frame.origin.y); 
NSLog(@"Image frame: %f, %f, location %f, %f", _imageView.frame.size.width, _imageView.frame.size.height, _imageView.frame.origin.x, _imageView.frame.origin.y); 
NSLog(@"Scroll frame: %f, %f, location %f, %f", _scrollView.frame.size.width, _scrollView.frame.size.height, _scrollView.frame.origin.x, _scrollView.frame.origin.y); 
NSLog(@"Content frame: %f, %f, location %f, %f", _scrollView.contentSize.width, _scrollView.contentSize.height, _scrollView.contentOffset.x, _scrollView.contentOffset.y); 
NSLog(@"Scroll frame zoom %f", [_scrollView zoomScale]); 

控制台输出为预期(我认为):

Parent frame: 351.000000, 200.000000, location 12.000000, 41.000000 
Image frame: 351.000000, 200.000000, location 0.000000, 0.000000 
Scroll frame: 351.000000, 200.000000, location 0.000000, 0.000000 
Content frame: 351.000000, 200.000000, location 0.000000, 0.000000 
Scroll frame zoom 1.000000 

这表明内容帧的大小与滚动视图和图像相同,BU它是如何含量稍大(该酒吧如所见),而价值观不支持?我可以垂直滚动图像,但它应该完全适合(水平适合)。

如果我在布局上将容器视图重新放置得较低,它会变得更好,所以会有些腥意。我花了几个小时试图找出什么是错误的,但找不到它,所以任何建议都非常感谢!

尝试设置self.edgesForExtendedLayout = UIRectEdgeNone

+0

这似乎是在正确的方向。但是,如果我将它放在容器视图中,它只会在父视图控制器中执行任何操作。这意味着内容会在导航栏下结束,但我可以手动抵消该内容。 – 2014-10-17 10:25:38

+0

@ LuukD.Jansen检查包含滚动视图'contentInset',也许它有'top'插入设置为非零值。 – 2014-10-17 11:11:52