niks
niks

Reputation: 554

Push-Pop kind Animation for UIViewController without using NavigationController

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.

Upvotes: 0

Views: 338

Answers (4)

g212gs
g212gs

Reputation: 849

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];

Upvotes: 0

pradeepa
pradeepa

Reputation: 4164

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

Upvotes: 0

Bhavesh Lathigara
Bhavesh Lathigara

Reputation: 1415

    - (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];
}

Upvotes: 1

Aman Aggarwal
Aman Aggarwal

Reputation: 3754

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.....

Upvotes: 1

Related Questions