简体   繁体   中英

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

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM