0
votes

I have 2 view controllers, lets call them ViewControllerA and ViewControllerB setup in a storyboard with autolayout. I want to animate a slide up/down animation between the 2 view controllers.

When started ViewControllerA is visible on screen. When an action is triggered I want ViewControllerB to slide down, so it's view.origin.y has a negative (-480) value at start and at end of animation it's view.origin.y is 0.

However when doing this animation Xcode nags about Unable to simultaneously satisfy constraints.

If want to animate going back from ViewControllerB to ViewControllerA with a slide up animation then ViewControllerAs view.origin.y is a positive value (480) at start and at end of animation it's view.origin.y is 0 and Xcode does not nag anything about constraints.

Is there something special I need to take into consideration when animating from a negative y value?

1

1 Answers

1
votes

Animate your constraints instead of the view's frame. Changing a view's frame while using auto layout can produce unexpected results and you should always consider it a no go. To animate a constraint all you need to do is call:

constraint.constant += 200 // where constraint is NSLayoutConstraint
view.setNeedsUpdateConstraints()
UIView.animateWithDuration(0.3) { () -> Void in
    view.layoutIfNeeded()
}