MegaManX MegaManX - 1 year ago 117
iOS Question

Adding non active constraints to existing UIView

I have

for which I have set constraints in IB. Now in code, i want to do some animation, by adding some new constraints and deactivating old. First I add new constraint to view, that is inactive, like this:

// camera view new constraints
self.cameraNewLeftConstraint = [NSLayoutConstraint constraintWithItem:self.cameraView
constant:0]; = NO;
[self.presentationView addConstraint:self.cameraNewLeftConstraint];

But this generates constraint warning during runtime (stnadard message - will attempt to break some constraints), that I have conflicting constraints, although I have added inactive constraint. How can I deal with this, how is this supposed to be done?

Answer Source

Views don't have inactive constraints. If you add a constraint to a view, then that constraint will be active.

The new method of setting the active property to YES adds the constraint to the proper view for you. In your code, when you called addConstraint, iOS added your constraint to your view, and changed active to YES.

So, don't call addConstraint on the view. Just create the constraint and set its active property to YES when you want it to be used.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download