我有一個包含所有UI元素的UIScrollView的應用程序。容器中的一個元素,它具有一個嵌入UIViewController的UIScrollView,其中包含UIImage和一些UILabels。容器視圖和滾動視圖呈現偏移的表示形式
然而,我在容器的UIScrollView中呈現的問題與UIImage一樣,它應該是填充整個可滾動內容,但頂部有一個欄。這個偏移很煩人,但也拋出了我對積分的計算。 (圖像應該填充整個圓邊界。
我設置的大小(使用約束)在含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它是如何含量稍大(該酒吧如所見),而價值觀不支持?我可以垂直滾動圖像,但它應該完全適合(水平適合)。
如果我在佈局上將容器視圖重新放置得較低,它會變得更好,所以會有些腥意。我花了幾個小時試圖找出什麼是錯誤的,但找不到它,所以任何建議都非常感謝!
這似乎是在正確的方向。但是,如果我將它放在容器視圖中,它只會在父視圖控制器中執行任何操作。這意味着內容會在導航欄下結束,但我可以手動抵消該內容。 – 2014-10-17 10:25:38
@ LuukD.Jansen檢查包含滾動視圖'contentInset',也許它有'top'插入設置爲非零值。 – 2014-10-17 11:11:52