Is it possible to animate a constraint in iOS 7 custom transition
Asked Answered
W

1

7

All I can seem to find in examples are using transforms or are modifying frames. Have I missed something obvious? Currently the other animations (fades) are all working fine, however the constraint stays locked in position.

A quick code snippet:

[[customViewController view] layoutIfNeeded];
[UIView animateWithDuration:2 animations:^{

    [[customViewController constraintToAnimate] setConstant:1024];
    [[customViewController view] layoutIfNeeded];

} completion:^(BOOL finished) {
    [transitionContext completeTransition:YES];
}];
Waisted answered 14/3, 2014 at 2:30 Comment(8)
Guess I should take that as a no..Waisted
I have exactly the same question. Any help or discovery?Nishanishi
I haven't found a way yet - I'm falling back to frame animation for nowWaisted
Thanks for reply. But I want to use autolayout in my UI. Can I mix autolayout and at the same time use frames in transitions? Thanks.Nishanishi
Yes frames work fine in the transitions - though you do have a lot more code to write.Waisted
No, you should not be updating frames manually if you are using auto layout, since the layout engine will change the frames out from under you to satisfy the constraints.Virg
Not during a custom transition. In normal code you're absolutely right and shouldn't touch the frames when using autolayout, however, in this case autolayout isn't working in a custom transition. Unless you can help us all out and provide some sample that proves otherwise?Waisted
Are you sure the value of the constant is different than 1024 before the animation block is executed ?Eusebiaeusebio
Z
0

You need to call layoutIfNeeded on the [[customViewController view] superview]

Zelaya answered 15/10, 2014 at 13:6 Comment(1)
Not sure if this was the answer back in the day but it was the most helpful. Testing in iOS 9 seems to just allow constraint manipulation directly without having to worry about the superview.Waisted

© 2022 - 2024 — McMap. All rights reserved.