This is my code
let view1 = UIView()
view1.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(view1)
view1.widthAnchor.constraint(equalToConstant: 100).isActive = true
view1.heightAnchor.constraint(equalToConstant: 100).isActive = true
view1.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
view1.centerYAnchor.constraint((equalTo: self.view.centerYAnchor).isActive = true)
The centerXAnchor of view1 is the same as the center of the Screen. However cneterYAnchor is not same.
I use NavigationBar, I think centerYAnchor of view1 shift by height of the NavigationBar.
So, if equalTo: superview.centerYAnchor
is possible, I can center the view.
Do you have any good ideas? I'm sorry I'm not good at English,,,