我一直在尝试寻找解决方案的快速版本,但无济于事。我想知道如何让我的 View Controller 滚动内容。现在它只是静态的,下面还有更多内容,我无法滚动。
class ProfileViewController: UIViewController, UICollectionViewDelegateFlowLayout {
let postsId = "postsId"
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(profileContainerView)
view.addSubview(profileTabCollection)
view.addSubview(containerForCollectionView)
view.addSubview(scrollView)
scrollView.widthAnchor.constraintEqualToConstant(view.frame.size.width).active = true
scrollView.heightAnchor.constraintEqualToConstant(view.frame.size.height).active = true
scrollView.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor).active = true
scrollView.centerYAnchor.constraintEqualToAnchor(view.centerYAnchor).active = true
scrollView.userInteractionEnabled = true
scrollView.scrollEnabled = true
scrollView.delegate = self
containerForCollectionView.widthAnchor.constraintEqualToConstant(scrollView.frame.size.width).active = true
containerForCollectionView.heightAnchor.constraintEqualToConstant(scrollView.frame.size.height).active = true
containerForCollectionView.topAnchor.constraintEqualToAnchor(profileTabCollection.bottomAnchor).active = true
profileContainerView.widthAnchor.constraintEqualToConstant(scrollView.frame.size.width).active = true
profileContainerView.heightAnchor.constraintEqualToConstant(250).active = true
profileContainerView.centerXAnchor.constraintEqualToAnchor(scrollView.centerXAnchor).active = true
profileContainerView.topAnchor.constraintEqualToAnchor(topLayoutGuide.bottomAnchor).active = true
profileTabCollection.widthAnchor.constraintEqualToAnchor(profileContainerView.widthAnchor).active = true
profileTabCollection.heightAnchor.constraintEqualToConstant(50).active = true
profileTabCollection.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor).active = true
profileTabCollection.topAnchor.constraintEqualToAnchor(profileContainerView.bottomAnchor).active = true
}
lazy var scrollView: UIScrollView = {
let sv = UIScrollView(frame: CGRectMake(0,0,1024,768))
sv.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * 3)
sv.translatesAutoresizingMaskIntoConstraints = false
return sv
}()
let containerForCollectionView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.purpleColor()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
最佳答案
有很多原因会导致这种方法行不通。由于您没有提供足够的信息来确定它是什么,我建议您仔细阅读本文(尤其是 Duncan C 的答案)。
how do i alter the position of a UIImage inside a imageView in SWIFT
关于ios - 如何滚动我的 UIViewController 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38912029/