View display animation

I added a button to the view (the view is the same size as the button). When you click this button, you need to display a new view. Thus, in the button event handler, I added a new view as a sub-item of the view on which the button was added, so that the new image will be displayed when the button is clicked. I need to do this when I click on the button, the newview should be called from top to bottom (it should look like it is sliding down from the view of the button). When the same button is pressed again, the new window has a scroll (slide) and disappears. I know that I need to apply some animated materials to get this effect. But I do not know how to do this. Could you help me give some ideas.

Thanks in advance!

+1
source share
1 answer

Well, you can animate the size of your window to simulate a slide on top:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
myView.frame = CGRectMake(0, buttonHeight+buttonTop, myView.frame.size.width, viewTargetHeight);
[UIView commitAnimations];

Make sure you set the height of the view to 0. When you create it.

To scroll it back, just do the opposite

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
myView.frame = CGRectMake(0, buttonHeight+buttonTop, myView.frame.size.width, 0);
[UIView commitAnimations];

If you really want your new view to slide, you can try to animate both the size and the position, and you also probably need to fix your animated view to a different view.

+1
source

Source: https://habr.com/ru/post/1711444/


All Articles