I try to create a UIView that is representing a page whose size is the same as the device screen. Since the app supports orientation, I am using AutoLayout to construct it.
It works fine until I try to animate the page to slide in from the right. Here is the best I could come up with after some research:
myView = UIView()
myView.backgroundColor = UIColor.orangeColor()
parentView.addSubview(myView)
myView.translatesAutoresizingMaskIntoConstraints = false
myView.leftAnchor.constraintEqualToAnchor(parentView.rightAnchor).active = true
myView.widthAnchor.constraintEqualToAnchor(parentView.widthAnchor).active = true
myView.heightAnchor.constraintEqualToAnchor(parentView.heightAnchor).active = true
UIView.animateWithDuration(Double(1.0), animations: {
self.myView.leftAnchor.constraintEqualToAnchor(self.parentView.leftAnchor).active = true
self.myView.layoutIfNeeded()
})
With the code above, the page myView
slides in from the top-left corner, which is not what I am expecting and the log also says Unable to simultaneously satisfy constraints
.
Any advise to help me and correct me for better understanding AutoLayout and animation is very much appreciated. Thanks.