制約を適用するコードを追加しました。ここにあなたの要件のコードです。一度試してみてください。行末のコメントをはっきりと見てください。
collectionView?.contentInset = UIEdgeInsets(top: 59, left: 0, bottom: 0, right: 0)
if let width = collectionView?.bounds.width {
let heaaderEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
//heaaderEffectView.frame = CGRectMake(0, 64, width, 59)
view.addSubview(heaaderEffectView)
heaaderEffectView.translatesAutoresizingMaskIntoConstraints = false
heaaderEffectView.addConstraint(NSLayoutConstraint(item: heaaderEffectView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: width))// for width of heaaderEffectView
heaaderEffectView.addConstraint(NSLayoutConstraint(item: heaaderEffectView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 59.0))// for height of heaaderEffectView
view.addConstraint(NSLayoutConstraint(item: heaaderEffectView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 64.0))// for y spacing that is top constraint to super view from heaaderEffectView
view.addConstraint(NSLayoutConstraint(item: heaaderEffectView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0.0))// for x spacing that is leading constraint to super view from heaaderEffectView
let headerView = DetailedReviewsHeader(frame: CGRectMake(0, 0, width, 59))// you can remove using frame but i kept it because i don't know what the initializer does with the frame
headerView.numberOfReviews = reviews?.count ?? 0
headerView.sortButton.addTarget(self, action: #selector(showSortOptions(_:)), forControlEvents: .TouchUpInside)
heaaderEffectView.contentView.addSubview(headerView)
headerView.translatesAutoresizingMaskIntoConstraints = false
heaaderEffectView.addConstraint(NSLayoutConstraint(item: headerView, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: heaaderEffectView, attribute: NSLayoutAttribute.Leading, multiplier: 1.0, constant: 0.0))// for leading 0
heaaderEffectView.addConstraint(NSLayoutConstraint(item: headerView, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: heaaderEffectView, attribute: NSLayoutAttribute.Trailing, multiplier: 1.0, constant: 0.0))// for trailing 0
heaaderEffectView.addConstraint(NSLayoutConstraint(item: headerView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: heaaderEffectView, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 0.0))// for top 0
heaaderEffectView.addConstraint(NSLayoutConstraint(item: headerView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: heaaderEffectView, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0.0))// for bottom 0
view.layoutIfNeeded()
}
はちょっと感謝:)最後に私が使用していますheaderEffectView.topAnchor.constraintEqualToAnchor(topLayoutGuide.bottomAnchorは、定数は:0) –
真= .activeは、それがあまりにもうまく動作します。しかし、多くのおかげで:) –
私は私のミスは、私は制約と再生する前にaddsubviewsていないと思う:) –