【发布时间】:2018-05-30 00:02:40
【问题描述】:
我在 MyView 文件中以编程方式创建了一个滚动视图。
let myScrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.isUserInteractionEnabled = true
return scrollView
}()
使用可视化格式语言,我将所有约束都设置为 superView。
func setupViews() {
self.frame = UIScreen.main.bounds
addSubview(myScrollView)
addConstraintsWithFormat(format: "H:|[v0]|", views: myScrollView)
addConstraintsWithFormat(format: "V:|[v0]|", views: myScrollView)
}
我的 scrollView 有一个按钮和一个标签。
在 viewDidLayoutSubviews 的 viewController 中,我设置了 contentSize:
myView.myScrollView.contentSize = CGSize(width: self.view.frame.size.width, height: self.view.frame.size.height + 200)
一切正常:我可以滚动,myScrollView 的高度完美,但宽度仅适用于 iPhone X。
以下是 iPhone SE 的示例:
ScrollView 比屏幕宽。在 iPhone Plus 中,它比屏幕小。
我做错了什么,我该如何解决?
提前谢谢你!
【问题讨论】:
-
您的问题解决了吗?
-
iDeveloper,还没有。正在处理这个...
-
使用该答案解决了问题 - stackoverflow.com/questions/19036228/…
标签: swift uiscrollview width scrollview