I'm seeing strange behaviour for a scrollview that I'm trying to horizontally centre on the device.
I've a scrollview, set up in viewDidLoad()
scrollView = UIScrollView()
scrollView.delegate = self
scrollView.minimumZoomScale = 0.
scrollView.maximumZoomScale = 2.0
scrollView.zoomScale = 1.0
scrollView.contentSize = CGSize(width: width, height: height)
and I've added a containerView for my content. I changed the background color here to try to be able to see what is going on
containerView = UIView()
containerView.backgroundColor = .black
scrollView.addSubview(containerView)
view.addSubview(scrollView)
To test this, I decided to set up a leading constant for the containerView (I'll centre it later).
containerView.translatesAutoresizingMaskIntoConstraints = false
view.addConstraint(NSLayoutConstraint(item: containerView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 50))
The view does seem to move 50 to the right. However 1) I lose the background color of containerView 2) containerView no longer seems to react to gestures
I thought I'd be smarter, and add the constraint to the scrollView instead - I keep the color and the gestures but it doesn't shift to the right.