In Objective-C, I usually set the "edgeForExtendedLayout" property to UIRectEdgeNone:
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) self.edgesForExtendedLayout = UIRectEdgeNone;
However, I would recommend binding restrictions to topLayoutGuide
func addScrollViewConstraints() { var scrollViewContraints = [NSLayoutConstraint]() scrollViewContraints.append(NSLayoutConstraint(item: scrollView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.topLayoutGuide, attribute:NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0.0)) scrollViewContraints.append(NSLayoutConstraint(item: scrollView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.bottomLayoutGuide, attribute:NSLayoutAttribute.Top, multiplier: 1.0, constant: 0.0)) scrollViewContraints.append(NSLayoutConstraint(item: scrollView, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute:NSLayoutAttribute.Leading, multiplier: 1.0, constant: 0.0)) scrollViewContraints.append(NSLayoutConstraint(item: scrollView, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute:NSLayoutAttribute.Trailing, multiplier: 1.0, constant: 0.0)) self.view.addConstraints(scrollViewContraints) }
Hope this works for you.
cr0ss
source share