【发布时间】:2013-05-25 18:40:39
【问题描述】:
我有一个带有 Frame = {X=20,Y=88,Width=728,Height=660} 的 UIContainerView 和一个嵌入其中的 UIScrollView。
UIScrollView 报告 Frame = {X=0,Y=0,Width=768,Height=960} 导致分页 UIScrollView 时宽度偏移 40(金色部分)。它导致以下输出向左分页一次:
但是,ContentSizeForViewInPopover 会报告预期的帧大小 = {Width=728, Height=660}。如何更正 UIScrollView 框架以具有正确的大小?
这是嵌入式 UIViewController 的 ViewDidLoad() 的代码:
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!)设置为超级视图的边界并为其提供适当的自动调整大小设置。
-
UIScrollView 设置在 UIView 上,该 UIView 位于 StoryBoard 上的 UIContainerView 内。 UIScrollView 没有显式创建。
标签: ios xamarin.ios uikit xamarin