nfoggia
nfoggia

Reputation: 513

iPhone subView animation: slide down

I have been searching for a while, but what i want is basically the "presentModalViewController" animation, but the other way... I want the top of the screen to fall to the bottom to reveal the page. Does anyone know what that is called?

This is the code i have so far, but it happens much too quickly... how would i slow it down?

-(void)gotToCreateGameViewController{
CreateNewGameViewController *newGame = [[CreateNewGameViewController alloc]initWithNibName:@"CreateNewGameViewController" bundle:nil];
self.createNewGameViewController = newGame;
createNewGameViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
[self presentModalViewController:newGame animated:YES];
[self.view insertSubview:newGame.view atIndex:0];

[newGame release];

Upvotes: 0

Views: 1881

Answers (3)

rakeshNS
rakeshNS

Reputation: 4257

Try this code

  -(void)gotToCreateGameViewController{
        CreateNewGameViewController *newGame = [[CreateNewGameViewController alloc]initWithNibName:@"CreateNewGameViewController" bundle:nil];
        self.createNewGameViewController = newGame;

        CATransition *transition = [CATransition animation];
        transition.duration = 0.05;
        transition.timingFunction = [CAMediaTimingFunction      
        functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        transition.type =kCATransitionMoveIn;
        CATransition *transition = [CATransition animation];
        transition.duration = 0.05;
        transition.timingFunction = [CAMediaTimingFunction      
        functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        transition.type =kCATransitionMoveIn;
        transition.subtype =kCATransitionFromTop;

        transition.delegate   = self;

        transition.subtype =kCATransitionFromTop;

        transition.delegate = self;


        [self presentModalViewController:newGame animated:NO];
        [self.view insertSubview:newGame.view atIndex:0];

        [self.view.layer addAnimation:transition forKey:nil]; 

        [newGame release];

Note that UIModalTransitionStyle will work only for iPad Application. See the Documentation.

Upvotes: 1

AMayes
AMayes

Reputation: 1767

My hackish answer:

If you move your initial view down to y = 960 (you'll probably have to add another view, then cut and paste everything into that view), and put your second view at y = 0, you can implement the following code. After instantiating a BOOL (I called mine movedUp):

-(void)moveView:(float)d{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:d];  

    CGRect rect = self.view.frame;
    if (!movedUp)
    {
        rect.origin.y -= 960;
        rect.size.height += 960;
    }
    else
    {
        // revert back to the normal state.
        rect.origin.y += 960;
        rect.size.height -= 960;
    }
    self.view.frame = rect;

    [UIView commitAnimations];
    movedUp = !movedUp;
}
- (void)viewDidAppear:(BOOL)animated
{
    [self moveView:0.0];
    [super viewDidAppear:animated];
}

Then I connected both buttons (one in each view) to the following:

-(IBAction)setViewMovedUp:(id)sender
{
    [self moveView:0.5];
}

Upvotes: 0

danh
danh

Reputation: 62686

I think you're looking for: UIModalTransitionStyleCoverVertical

Presentation Transition Styles
Transition styles available when presenting view controllers.

typedef enum {
        UIModalTransitionStyleCoverVertical = 0,
        UIModalTransitionStyleFlipHorizontal,
        UIModalTransitionStyleCrossDissolve,
        UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;

It goes bottom-to-top to present, then top-to-bottom upon dismiss. To transition top-to-bottom, you'll need to roll your own, or start with the destination vc underneath and modally present the start vc.

Upvotes: 2

Related Questions