2013-05-25 63 views
2

我有一個Frame = {X = 20,Y = 88,Width = 728,Height = 660}的UIContainerView和嵌入其中的UIScrollView。容器視圖中的UIScrollView具有不正確的幀大小

UIScrollView報告Frame = {X = 0,Y = 0,Width = 768,Height = 960},當分頁UIScrollView時,會導致寬度偏移40(黃金部分)。它導致具有尋呼一次向左以下輸出:

enter image description here

然而,ContentSizeForViewInPopover報告預期幀大小= {寬度= 728,高度= 660}。我如何糾正UIScrollView框架的大小?

下面是viewDidLoad中()中的嵌入式的UIViewController的代碼:

var pages = PageControl.Pages = 2; 
Console.WriteLine("ScrollView Frame: {0}", ScrollView.Frame); 

for(int i = 0; i < pages; i++) 
{ 
    RectangleF frame 
    frame.X = ScrollView.Frame.Width * i; // expected {728 * i} but is {768 * i} 
    frame.Y = 0; 
    frame.Size = ScrollView.Frame.Size; 

    Console.WriteLine("Subview frame: {0}", frame); 

    ScrollView.AddSubview(
     new UIView(frame) { 
      Bounds = frame, 
      BackgroundColor = GetRandomColor() 
     }); 
    } 

    ScrollView.ContentSize = new SizeF(ScrollView.Frame.Width * pages, ScrollView.Frame.Height); 
    Console.WriteLine("ScrollView ContentSize = {0}", ScrollView.ContentSize); 
+0

凡在你的代碼中創建的UIScrollView?您必須將其Frame(不是ContentSize!)設置爲超級視圖的界限,並給予適當的自動調整大小設置。 – Krumelur

+0

UIScrollView設置在放置在StoryBoard上的UIContainerView中的UIView上。 UIScrollView沒有明確創建。 – sduplooy

回答

2

仔細檢查在IBUIViewController下,根據屬性檢查員,佈局部分,該「調整滾動查看插圖」沒有被檢查。我有一個類似的問題,讓我絆倒了一段時間,這是我需要做的,以獲得正確的佈局。

0

在IOS 7.0中 使用self.automaticallyAdjustsScrollViewInsets = NO;在ViewDidLoad

-2

嘗試在代碼中創建您的UIScrollView,顯然設計器會覆蓋您在代碼中應用的任何調整。

1

call [self.ScrollView layoutIfNeeded];這條線

frame.X = ScrollView.Frame.Width * i; // expected {728 * i} but is {768 * i} 

它與我之前,古德勒克

相關問題