I have a collectionview and other views inside a scrollview. I need to add constraint programmatically to make sure it works on all devices.
CollectionView/Gallery is inside the UIScrollView. It works before the constraint.
I am using the code below to stick the collectionview to the right but I am getting error terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal. constraint:
//constraint
NSLayoutConstraint *bottomSpaceConstraint = [NSLayoutConstraint constraintWithItem:self.galleryView
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.scrollView
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:0.0];
[self.galleryView addConstraint:bottomSpaceConstraint];
scrollView, not thegalleryView. As an aside, I might be inclined to call the constraint variablerightSpaceConstraint, to make it clear its the right constraint, not the bottom constraint.