如何在Swift 5中添加滚动视图? [英] How to add Scroll View in Swift 5?

查看:65
本文介绍了如何在Swift 5中添加滚动视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在项目中添加滚动视图,但是在Swift 5中我无法添加,我尝试了很多方法

I wanna add scroll view in my project but in swift 5 I can't add it I tried many ways

@IBOutlet weak var scrollView: UIScrollView! 
@IBOutlet weak var imageViewBottomConstraint: NSLayoutConstraint!
@IBOutlet weak var imageViewLeadingConstraint: NSLayoutConstraint!
@IBOutlet weak var imageViewTopConstraint: NSLayoutConstraint!
@IBOutlet weak var imageViewTrailingConstraint: NSLayoutConstraint!

推荐答案

如果首先使用界面构建器,请添加滚动视图并将滚动视图约束(顶部,底部,前导和尾随)设置为(0,0,0,0).视图层次结构必须类似于 view->滚动视图->视图(内容视图).再次为您的内容视图添加约束.内容视图必须与父视图(Scroll View)具有相同的宽度和高度.控制从内容视图拖动到文档大纲

If you use interface builder first of all add your scroll view and set scroll view constraint (top, bottom, leading and trailing) as (0,0,0,0). View hierarchy must be like this view -> scroll view -> view(content view). Again add constraints for your content view. Content view must have equal width and equal height with parent view (Scroll View). Control drag from content view to scroll view in Document Outline

有关更多信息,请参见以下 https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithScrollViews.html

For more information you can look at this https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithScrollViews.html

这篇关于如何在Swift 5中添加滚动视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆