El contenido no cambia correctamente en una UIView

A continuación se muestra mi código:

SecondView *sview=[[SecondView alloc] init];
        [self.view addSubview:[sview view]];
        sview.view.layer.cornerRadius=20;
        CGRect rect=sview.view.frame;
        CGRect bound=sview.view.bounds;
        [sview.view setFrame:CGRectMake(rect.origin.x, btn.frame.origin.y, rect.size.width, 0)];
        [sview.view setBounds:CGRectMake(0, 0, bound.size.width, 0)];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1];
        [sview.view setFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
        [sview.view setBounds:CGRectMake(0, 0, bound.size.width, bound.size.height)];
        [sview.view setTag:10];
        [UIView commitAnimations];

I am trying to expand a subview from invisible to visible. In other words, I want to expand a view from one line to a block. The view is a very simple view that I create from IB. There are some buttons on it. When the code runs, the view itself works well. However, the buttons work incorrectly. The buttons move into the view from outside. What I want is the button not to move. Rather, they should expand like the view.

¿Alguien me ayudaría?

Atentamente,

preguntado el 08 de noviembre de 11 a las 14:11

1 Respuestas

You are only animating the view's frame and bounds, all subviews are not animated with that code. Try using the scale animation, like

sview.view.transform = CGAffineTransformMakeScale(0.01, 0.01);

[UIView beginAnimations:@"animations" context:NULL];

sview.view.transform = CGAffineTransformMakeScale(1.0, 1.0);

[UIView commitAnimations];

This should first shrink your view and all it's subviews to a point, and then expand it in the animation to its original size.

respondido 08 nov., 11:19

thank you very much. It works, one more question, at the moment, it shrink from the center of the view, if I want it shrink from the buttom, what should I do? - Yongwei Xing

you could maybe combine it with a slide transition, or translate the y coordinate. - El ojo

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.