在 scrollView 中对 contentView 设置约束
setting constraints on contentView inside scrollView
对于我的项目,我需要制作一个自顶部高度为 64 pt 的自定义菜单。因此默认导航栏可见性设置为 false。在此菜单下,我有一个 ScrollView,其中包含一个 ContentView,我将在其中放置所有 UI 项目。 ContentView 的原点,在 ScrollView 内部,是 (0,0)。问题是,当我 运行 从 SrcollView 顶部离开 20 pt space 后显示项目 ContentView。
这是示例项目 link:https://drive.google.com/file/d/0BzhZns5G0PXhN2lNSjF6XzNmTTg/view?usp=sharing
从您的代码中删除:
var gg:CGSize = CGSize(width: self.contentView.frame.width, height: self.contentView.frame.height)
self.scrollView.contentSize = gg
并添加此行而不是该代码:
scrollView.contentInset = UIEdgeInsets(top: -20, left: 0, bottom: 0, right: 0)
我已经给你改好了,用这个吧。 https://drive.google.com/file/d/0B97G6aGaHcoYNUVtMmN1b1dUR2M/view?usp=sharing
这是滚动视图和 Table 视图中常见的问题。添加这行代码来解决它:
self.automaticallyAdjustsScrollViewInsets = false;
对于我的项目,我需要制作一个自顶部高度为 64 pt 的自定义菜单。因此默认导航栏可见性设置为 false。在此菜单下,我有一个 ScrollView,其中包含一个 ContentView,我将在其中放置所有 UI 项目。 ContentView 的原点,在 ScrollView 内部,是 (0,0)。问题是,当我 运行 从 SrcollView 顶部离开 20 pt space 后显示项目 ContentView。
这是示例项目 link:https://drive.google.com/file/d/0BzhZns5G0PXhN2lNSjF6XzNmTTg/view?usp=sharing
从您的代码中删除:
var gg:CGSize = CGSize(width: self.contentView.frame.width, height: self.contentView.frame.height)
self.scrollView.contentSize = gg
并添加此行而不是该代码:
scrollView.contentInset = UIEdgeInsets(top: -20, left: 0, bottom: 0, right: 0)
我已经给你改好了,用这个吧。 https://drive.google.com/file/d/0B97G6aGaHcoYNUVtMmN1b1dUR2M/view?usp=sharing
这是滚动视图和 Table 视图中常见的问题。添加这行代码来解决它:
self.automaticallyAdjustsScrollViewInsets = false;