容器视图中的UIScrollView具有不正确的帧大小
问题描述:
我有一个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);
答
仔细检查在IB
父UIViewController
下,根据属性检查员,布局部分,该“调整滚动查看插图”没有被检查。我有一个类似的问题,让我绊倒了一段时间,这是我需要做的,以获得正确的布局。
答
在IOS 7.0中 使用self.automaticallyAdjustsScrollViewInsets = NO;在ViewDidLoad
答
尝试在代码中创建您的UIScrollView,显然设计器会覆盖您在代码中应用的任何调整。
答
call [self.ScrollView layoutIfNeeded];这条线
frame.X = ScrollView.Frame.Width * i; // expected {728 * i} but is {768 * i}
它与我之前,古德勒克
凡在你的代码中创建的UIScrollView?您必须将其Frame(不是ContentSize!)设置为超级视图的界限,并给予适当的自动调整大小设置。 – Krumelur
UIScrollView设置在放置在StoryBoard上的UIContainerView中的UIView上。 UIScrollView没有明确创建。 – sduplooy