0

我在iOS 中有一个以编程方式生成的集合视图,即它没有笔尖。然后将其注入到页面上的视图中。我正在使用 Xamarin Studio 和 MVVM Cross。当我运行应用程序时,会生成集合并将其注入正确的位置。但是当我向下滚动并且滚动条到达集合视图的底部时,它会继续滚动,但滚动条会离开屏幕底部。

我认为集合视图没有遵守我将其注入的视图的尺寸,因此它的高度太高了。我可以在代码中设置集合的高度吗?

编辑

好的,当我使用 MVVM 时,我找到了一种方法来实现我在问题中解释的内容。

我已经设法让我的集合视图遵守它被注入的视图的顶部和底部。我通过使用来自 Stuart Lodge http://slodge.blogspot.co.uk/2013/07/playing-with-constraints.html的 Cirrious 库Cirrious.FluentLayouts.Touch来完成这项工作。有了这个,我消除了在集合视图上指定高度的需要,而是告诉它坚持父视图的顶部和底部。

例如

//Add constraints between collection view and its container in page
parentView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
parentView.AddConstraints(
  collectionsView.AtTopOf(parentView,0),
  collectionsView.AtBottomOf(parentView,0),
  collectionsView.AtLeftOf(parentView,0),
  collectionsView.AtRightOf(parentView,0)
);
4

2 回答 2

2

好的,当我使用 MVVM 时,我找到了一种方法来实现我在问题中解释的内容。

我已经设法让我的集合视图遵守它被注入的视图的顶部和底部。我通过使用来自 Stuart Lodge http://slodge.blogspot.co.uk/2013/07/playing-with-constraints.html的 Cirrious 库 Cirrious.FluentLayouts.Touch 来完成这项工作。有了这个,我消除了在集合视图上指定高度的需要,而是告诉它坚持父视图的顶部和底部。

例如

//Add constraints between collection view and its container in page
parentView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
parentView.AddConstraints(
  collectionsView.AtTopOf(parentView,0),
  collectionsView.AtBottomOf(parentView,0),
  collectionsView.AtLeftOf(parentView,0),
  collectionsView.AtRightOf(parentView,0)
);

注意 如果您正在使用 nib 文件 ( .xib ) 中已经存在的元素,那么如果您尝试添加的约束开始发生冲突,您可能需要在添加约束之前添加以下行。

parentView.removeConstraints(constraints: parentView.Constraints)
于 2013-10-01T08:03:48.633 回答
1

在 FluentLayout 上查看我关于自动布局的一些演示

https://www.evernote.com/l/AJPLFfvOaXVLxZNme8s9_PjjaazwRP-Bl9Y

问候,特隆。

于 2015-07-21T08:29:13.083 回答