我在viewDidLoad
:
let childViewControllerForPosts = PostsCollectionViewController(collectionViewLayout: UICollectionViewLayout())
let cView = childViewControllerForPosts.view
self.view.backgroundColor = UIColor.redColor()
self.addChildViewController(childViewControllerForPosts)
self.view.addSubview(cView)
childViewControllerForPosts.didMoveToParentViewController(self)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleScroll(_:)), name: "cvScrolled", object: nil)
cView.widthAnchor.constraintEqualToConstant(view.frame.size.width).active = true
cView.heightAnchor.constraintEqualToConstant(view.frame.size.height).active = true
cView.topAnchor.constraintEqualToAnchor(containerForGreyAndPurple.bottomAnchor).active = true
cView.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor).active = true
然而,我得到一个错误,说这是非法约束,因为它没有共同的祖先:(
这是错误:
...because they have no common ancestor. Does the constraint reference items in different view hierarchies? That's illegal.'