Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

constraints for child view controllers in scroll view not working as expected

$
0
0

I have two child view controllers in the content view of a scroll view. the first one is constrained to the top of the contentview, the second is constrained to the top of the first view controller.

The problem: the second view controller is not appearing as expected based on constraints (second view controller is colored box at the top, first is box below that).

second view controller is colored box at the top, first is box below that

Is it a problem with the scroll view or my constraints?

scrollview setup:

  • content view constrained to scrollview not frame layout
  • scroll view constrained to superview safe area
  • content view width equal to superview

here's my constraints code

 override func viewDidLoad() {        super.viewDidLoad()        contentView.addSubview(planningSessionVC.view)        contentView.addSubview(attendeesVC.view)        scrollViewRightHidden = scrollView.rightAnchor.constraint(equalTo: view.leftAnchor, constant: 0)        scrollViewRight = scrollView.rightAnchor.constraint(equalTo: view.rightAnchor)        scrollViewLeft = scrollView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0)        planningSessionTop = planningSessionVC.view.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 60)        NSLayoutConstraint.activate([            planningSessionVC.view.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 15),            planningSessionVC.view.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -15),            planningSessionTop!,            scrollView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 1.0)            ])        view.layoutIfNeeded()        NSLayoutConstraint.activate([        attendeesVC.view.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 15),        attendeesVC.view.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -15),        attendeesVC.view.topAnchor.constraint(equalTo: planningSessionVC.view.bottomAnchor, constant: 0),        attendeesVC.view.heightAnchor.constraint(equalToConstant: 50),        attendeesVC.view.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 20)        ])        view.layoutIfNeeded()    }

Viewing all articles
Browse latest Browse all 12141

Trending Articles