iPhone子视图动画:向下滑动

时间:2012-04-24 17:32:36

标签: iphone animation subview

我一直在寻找,但我想要的基本上是“presentModalViewController”动画,但另一种方式......我希望屏幕顶部落到底部以显示页面。有谁知道这叫什么?

这是我到目前为止的代码,但它发生得太快了......我怎么会放慢它的速度呢?

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

3 个答案:

答案 0 :(得分:2)

我认为您正在寻找:UIModalTransitionStyleCoverVertical

Presentation Transition Styles
Transition styles available when presenting view controllers.

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

从底部到顶部呈现,然后在解雇时从上到下。要从上到下进行转换,您需要自己滚动,或者从下面的目标vc开始,并以模态方式显示start vc。

答案 1 :(得分:1)

试试此代码

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

请注意,UIModalTransitionStyle仅适用于iPad应用程序。请参阅文档。

答案 2 :(得分:0)

我的hackish回答:

如果您将初始视图向下移动到y = 960(您可能需要添加另一个视图,然后将所有内容剪切并粘贴到该视图中),并将第二个视图放在y = 0,您可以实现以下码。实例化BOOL(我称之为我的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];
}

然后我将两个按钮(每个视图中一个)连接到以下内容:

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