Below is my code:
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.
Would someone help me?
Best Regards,
You are only animating the view’s frame and bounds, all subviews are not animated with that code. Try using the scale animation, like
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.