我有一個Frame = {X = 20,Y = 88,Width = 728,Height = 660}的UIContainerView和嵌入其中的UIScrollView。容器視圖中的UIScrollView具有不正確的幀大小
UIScrollView報告Frame = {X = 0,Y = 0,Width = 768,Height = 960},當分頁UIScrollView時,會導致寬度偏移40(黃金部分)。它導致具有尋呼一次向左以下輸出:
然而,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);
凡在你的代碼中創建的UIScrollView?您必須將其Frame(不是ContentSize!)設置爲超級視圖的界限,並給予適當的自動調整大小設置。 – Krumelur
UIScrollView設置在放置在StoryBoard上的UIContainerView中的UIView上。 UIScrollView沒有明確創建。 – sduplooy