1
votes

I want to implement Push/Pop kind of animation in my application. Currently in my application, I'm simply adding & removing viewcontroller using addsubview & removesubview without any animation.

Adding navigation controller will be a major change in application as it will change whole structure of application. Is there any way to implement such kind of animation with using navigation controller.

4

4 Answers

1
votes

Try this

first give your subview a frame

     secondview.frame=CGRectMake(330, 0, 320, 460);

Then when you are adding it

   [self.view addSubView:secondview];

   [UIView beginAnimations:@"bringViewDown" context:nil];
   [UIView setAnimationDuration:0.2];
   firstview.frame=CGRectMake(-330, 0, 320, 460);
   secondview.frame=CGRectMake(0, 0, 320, 460);
   [UIView commitAnimations];

Hope this helps.....

1
votes
    - (void)viewDidLoad
    {
        [super viewDidLoad];

        viewSecond.frame = CGRectMake(330, 0, 320, 548);
    }


- (IBAction)onBtnClick:(id)sender
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    viewFirst.frame = CGRectMake(-330, 0, 320, 548);
    viewSecond.frame = CGRectMake(0, 0, 320, 548);
    [UIView commitAnimations];
}
- (IBAction)onBtnClick2:(id)sender
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    viewFirst.frame = CGRectMake(0, 0, 320, 548);
    viewSecond.frame = CGRectMake(330, 0, 320, 548);
    [UIView commitAnimations];
}
0
votes

Implement custom container controller refer Session 102 - Implementing UIViewController Containment in WWDC 2011

0
votes

Add subview with push animation

//push animation
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.layer addAnimation:transition forKey:nil];
[self addSubview:subView];

and remove subview with pop animation

//pop animation
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.superview layer] addAnimation:animation forKey:@"SlideView"];
[self removeFromSuperview];