Nanoc
Nanoc

Reputation: 2381

IOS Animations without navigation controller

In my app im showing different screen this way:

info = [[Info alloc]initWithNibName:@"Info" bundle:nil];
[self.view addSubview:info.view];

Info is a subclass of UIViewController, so i just create it and add it as a subview of the current view.

When i want to dismiss it i just do:

[self.view removeFromSuperview];

Im not sure if this is the right way of doing it, but yesterday apple has published on app store another app that do the same to display views.

My question is, how can i animate the transition between views, so when i call addsubview it do the animation?

I tried this:

        info = [[Info alloc]initWithNibName:@"Info" bundle:nil];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                               forView:info.view
                                 cache:YES];
        [self.view addSubview:info.view];
        [UIView commitAnimations];

But its not working, this dont do anything.

Upvotes: 0

Views: 574

Answers (4)

Gyanendra
Gyanendra

Reputation: 361

You can use CATransition for that kind of animation without using navigationcontroller below is the code

Info *infoViewController = [[Info alloc]init];
CATransition *transition = [CATransition animation];
transition.duration = 0.50;
transition.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;
UIView *containerView = self.view.window;
[containerView.layer addAnimation:transition forKey:nil];
[self presentModalViewController:infoViewController animated:NO];

Like this you can animate the view from left to right without using navigationcontroller.

Upvotes: 1

Nirav Gadhiya
Nirav Gadhiya

Reputation: 6342

to add a view controller's view use this

ChildViewController * child = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                           forView:info.view
                             cache:YES];
[self.view addSubview:child.view];
[UIView commitAnimations];

[self addChildViewController:child];
[child release];//for NON ARC

to remove view use this...

for (UIViewController *childVC in [self childViewControllers])
{
    [childVC removeFromParentViewController];
}
[self.view removeFromSuperview];// YOU CAN ADD ANIMATIONS HERE
[self removeFromParentViewController];

HOPE this will help you, It is working fine for me....

Upvotes: 1

Anil
Anil

Reputation: 2438

You can give UIView Block Animation a shot. Something like this:

[UIView animateWithDuration:.25 delay:0 options:UIViewAnimationOptionAllowUserInteraction  animations:^
     {
         requiredView.frame = CGRectMake(0, 300.0, 400.0, 180.0);

     } completion:^(BOOL finished)
     {
     }];

You can set the view's frame and position it outside the viewing co-ordinates and then change the frame accordingly to animate the UIView.

Upvotes: 0

Eimantas
Eimantas

Reputation: 49335

It's not the right way to manage view hierarchy. You should use view controller methods for this (addChildViewController: & removeFromParentViewController). Then you can use method transitionFromViewController:toViewController:options:animations:completion: (or something like that) to do various animations.

Upvotes: 4

Related Questions