Ios UIScrollView中包含子视图的UIView

Ios UIScrollView中包含子视图的UIView,ios,uiscrollview,xamarin,xcode6,Ios,Uiscrollview,Xamarin,Xcode6,我有一个包含滚动视图的视图。这个Scrollview包含一个UIView(称为ContentView),它又有两个子视图,我想在它们之间滚动 运行时,以下是各种视图的值: ContentView(在UIScrollView中): ContentView中的子视图(UIView): 一, 二, 滚动视图: Width: 640 Height: 568 Width: 320 Height: 568 ContentSize: Width: 640 Height: 568 我以编程方式(使

我有一个包含滚动视图的视图。这个Scrollview包含一个UIView(称为ContentView),它又有两个子视图,我想在它们之间滚动

运行时,以下是各种视图的值:

ContentView(在UIScrollView中):

ContentView中的子视图(UIView):

一,

二,

滚动视图:

  Width: 640
  Height: 568
Width: 320
Height: 568
ContentSize: 
Width: 640
Height: 568
我以编程方式(使用for循环)将子视图添加到内容视图中,然后相应地更改ContentView的
界限
,以及ScrollView的
内容大小
,如下所示:

for (var i = 0; i < 2; i++) {
    var page = ViewModel.Items[i];
    var pageView = CreatePage(page);
    pageView.Frame = new CGRect(View.Bounds.Width*i, 0, View.Bounds.Width, View.Bounds.Height);
    ContentView.Add (pageView);
}

ContentView.Frame = new CGRect (0, 0, View.Bounds.Width * 2, View.Bounds.Height);
ScrollView.ContentSize = new CGSize (ContentView.Bounds.Width, ContentView.Bounds.Height);
for(变量i=0;i<2;i++){
var page=ViewModel.Items[i];
var pageView=CreatePage(第页);
pageView.Frame=newCGRECT(View.Bounds.Width*i,0,View.Bounds.Width,View.Bounds.Height);
添加(页面视图);
}
ContentView.Frame=新的CGRect(0,0,View.Bounds.Width*2,View.Bounds.Height);
ScrollView.ContentSize=新的CGSize(ContentView.Bounds.Width,ContentView.Bounds.Height);
当我加载应用程序时,我得到的是:

只有一个子视图未启用滚动。如何使水平滚动正常工作


感谢您的回复!:-)

您设置ContentView.Frame和ScrollView.ContentSize的方式不对。scrollview的框架应与屏幕的边界相同,而contentSize应与实际内容的大小相等

除非内容大小大于实际UIScrollview实例的框架,否则UIScrollview不会滚动

ContentView.Frame = new CGRect (0, 0, View.Bounds.Width, View.Bounds.Height);
ScrollView.ContentSize = new CGSize (ContentView.Bounds.Width*2, ContentView.Bounds.Height);

您将ContentView.Frame和ScrollView.ContentSize设置错误。scrollview的框架应与屏幕的边界相同,而contentSize应与实际内容的大小相等

除非内容大小大于实际UIScrollview实例的框架,否则UIScrollview不会滚动

ContentView.Frame = new CGRect (0, 0, View.Bounds.Width, View.Bounds.Height);
ScrollView.ContentSize = new CGSize (ContentView.Bounds.Width*2, ContentView.Bounds.Height);

我可能解释得不太清楚。
ContentView
位于ScrollView内部,这就是我显式设置ContentView宽度的原因。ScrollView边界与屏幕相同,其ContentSize是屏幕宽度的两倍。我更新了问题以反映这一点。我可能解释得不太清楚。
ContentView
位于ScrollView内部,这就是我显式设置ContentView宽度的原因。ScrollView边界与屏幕相同,其ContentSize是屏幕宽度的两倍。我更新了问题以反映这一点。
ContentView.Frame = new CGRect (0, 0, View.Bounds.Width, View.Bounds.Height);
ScrollView.ContentSize = new CGSize (ContentView.Bounds.Width*2, ContentView.Bounds.Height);