1

I would like to animate my view in response to a user action to look like the animation for a pushviewcontroller. That is, I want the view to slide off-screen to the left in response to the user action. However, I don't want to create a new view and push it onto the stack using pushviewcontroller. I want to reuse the same view and reload the data, and I want the reloaded view with the new data to slide in from the right, and it would in the animation for pushviewcontroller. How would you do this?

Thanks for any help!

Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
Paul
  • 279
  • 5
  • 14

2 Answers2

2

Do this in your viewController. This will move the whole view of it to the right and then after 2 seconds back. You may want to move only a subview so you have some kind of background.

- (void)viewDidAppear:(BOOL)animated
{
    [UIView animateWithDuration:1.2 
                     animations:^{
                         self.view.frame = CGRectMake(320, 0, 320, 480);
                     }];

    [self performSelector:@selector(slideBackView) withObject:nil afterDelay:2.0];
}

- (void)slideBackView
{
    [UIView animateWithDuration:1.2 
                     animations:^{
                         self.view.frame = CGRectMake(0, 0, 320, 480);
                     }];
}
Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
  • thanks! this is almost what I want. I can make the view slide off the screen and come back on. To simulate the pushviewcontroller animation, I make the view slide off to the left and slide in from the right again. However, between the two slides, the background is white, since it has to wait until the first view slides off before the second view can slide in. is there any way to connect the two views so there is no white background shown, as in the pushviewcontroller animation? – Paul Apr 07 '11 at 20:38
  • Yes of coure, just do the animation with two views. Don't use self.view but something like firstView.frame and secondView.frame in the animation blocks. Just add some properties and reference those views. – Nick Weaver Apr 07 '11 at 20:44
  • ok thanks! I've been able to get rid of the whitespace between the two views, as you said. To do this, I've been creating another view, and animating it in conjunction with the original view. I put in the second view using addSubview. However, this seems to load the view onto the stack of subviews. When I try to discard the second view using removeFromSuperview, the animation for the second view doesn't work, because it removes the second view before animating it. How can I take care of this? Should I use something other than addSubview? Should I call removeFromSuperview elsewhere? – Paul Apr 09 '11 at 22:13
  • Question is: do you want to get rid off the subview? if yes do the snimation first and call performSelector on the view which should be removed with a delay as long as the animation is: the animation is processed and afterwards its view is removed. – Nick Weaver Apr 10 '11 at 02:57
0

you can animate your UIView,See the below SO post ..

iPhone UIView Animation Best Practice

Here is more link ..

http://ameyashetti.wordpress.com/2009/08/17/view-animation-tutorial/

Community
  • 1
  • 1
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76