Combining autoplay with basic animation

I am new to mainstream animation, and I'm struggling with one task - how to combine autostart with mainstream animation. In fact, I found only one suggestion in the Core Animation documentation that relates to Autolayout, it is

Remember to update the viewing restrictions as part of your animation. If you use constraint-based layout rules to control the position of your views, you must remove any restrictions that may interfere with the animation as part of the setting for this animation. Limitations affect any changes you make to the position or size of the view. They also influence the relationship between the look and his views on the child. If you animate changes to any of these elements, you can remove the restrictions, make changes, and then apply any new restrictions.

But since I tried everything, it is not as it may seem. Here is my script.

I developed a sliding menu that uses autorun widely. Here is a view of this point of view. enter image description here

I use autodetection constraints to force proportional positioning of these items in a sliding menu. In fact, there are many restrictions, and I did not want to publish all those that were in my question, and maybe they are not needed to directly answer this question, however, if you need them, I can update the message with those restrictions.

The animation you see in the gif was achieved only with auto-detection. I just added an exit to the height limit of the sliding menu and changed it like this: (the code is written using Xamarin Monotouch, but I believe it should be clear what is being done here for pure iOS developers)

private void AnimateSlideMenuAppearance() { float height; if (isSlideMenuShown) { height = 0; } else { height = slideMenuHeight; } UIView.Animate (0.4, delegate { this.slideMenuHeightConstraint.Constant = height; this.View.LayoutIfNeeded (); }, delegate { isSlideMenuShown = !isSlideMenuShown; }); } 

Now I want to get a more sophisticated look. CLICK HERE to see the effect I want to achieve.

Just to try, I tried to implement the disappearing part of this animation with the CABasicAnimation s series, but it was unsuccessful, I get strange behavior.

Can anyone suggest what should I do here? Is it possible to use autostart to calculate viewing positions, but somehow override the animation between autostart size changes? I mean in my specific example, instead of proportionally reducing the size of all the buttons in the menu. I need to add FadeOut animations to them, animate the borders to zero, and also drastically increase the start time of the animation from button to button to get the effect that I want. Or maybe I need to completely get rid of autostart and manually calculate the size and animation?

What is the best practice in these scenarios β€” when you have complex auto-auditing and need custom Core Animation transitions between autostart changes? Hope I have described this question well. Thank you for your responses.

+6
source share
1 answer

This is entirely feasible, although it can be difficult just because it looks like your desired cases will have multiple animations.

However, I noticed one thing in your code that is odd: you change the constant in the constraint ( this.slideMenuHeightConstraint.Constant = height ) in the animation block, not in front of it. For almost all cases, I can imagine you have to change the restriction in front of the animation block. Constraints are not visually displayed until the next user interface start loop (or setNeedsUpdateConstraints is enforced for the next loop) or immediately to layoutIfNeeded . And since [UIView animate:...] does this for you, layoutIfNeeded should (as a rule) be the only one in your animation block when animating autostart.

In your case, you will have to make the animation somewhat reactive, however, for example, if you want to add these buttons, as in the example, and make them appear, animate and grow. After calling layoutIfNeeded you can safely check the frame size. If it exceeds your threshold (or some other indicator), you can activate the animation of the buttons. (So ​​yes, this may be the case when I add more code inside the animation block - check the threshold, start another animation, etc.).

0
source

All Articles