ios - 如何滚动我的 UIViewController 内容?

标签 ios swift uiscrollview xcode7.2

我一直在尝试寻找解决方案的快速版本,但无济于事。我想知道如何让我的 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/

相关文章:

ios - 是否有某种方法可以让每个应用程序都使用单个 NSManagedObjectContext 进行读取和写入?

swift - 如何以编程方式快速查找在 OSX 中接收/发送的网络数据?

ios - 向 UIScrollView 添加 subview

swift - UIScrollView Delegate 作为协议(protocol)默认实现

ios - 将自定义 UIView 更改为 UIScrollView

ios - 在 Swift 中添加图像过渡动画

ios - 我在 Xcode7 上遇到字符串错误

ios - swift : show another view controller on swipe up in first view controller

ios - Realm 对象改变了,那个对象的另一个副本也改变了,为什么?

ios - 未在新版本的 testflight 中显示内部测试人员的更新