【问题标题】:UIViewController with UIScrollView带有 UIScrollView 的 UIViewController
【发布时间】:2015-02-13 17:08:04
【问题描述】:

我正在尝试将 UIViewControllers 视图更改为滚动视图以供使用:

def loadView
  super
  scrollView = UIScrollView.alloc.initWithFrame(UIScreen.mainScreen.bounds)
  self.view = scrollView
  # Tried experimenting with this
  # self.view.contentSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width,, UIScreen.mainScreen.bounds.size.height)
  self.view.backgroundColor = UIColor.whiteColor
end

然后我将子视图添加到viewDidLoad 内部的self.view,在每个子视图上使用subview.setTranslatesAutoresizingMaskIntoConstraints(false),然后使用NSLayoutConstraint.constraintsWithVisualFormat 设置约束。

约束正常工作,但是一旦我将视图更改为滚动视图,一切都会变得一团糟:

“标题”字段应与导航栏齐平,并且两个字段都应填满屏幕宽度。

红色框只是展示了子视图的宽度。

【问题讨论】:

    标签: ios objective-c iphone uiscrollview rubymotion


    【解决方案1】:

    有时很难让 UIViews 在 UIScrollView 内使用 autoLayout。我在这些情况下所做的是设置一个 containerView,它用 autoLayout 中的约束和定位填充 UIScrollView 的四个边缘。然后在这个容器中我添加我想要的东西,我总是要做的一件事是跟踪这个容器的高度,并使其随着添加到其中的子视图相应地增长。这种方式实现视图层次结构有点困难,但约束变得更有条理。 以下是 Apple 关于如何快速完成此操作的说明:https://developer.apple.com/library/ios/technotes/tn2154/_index.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多