【问题标题】:iPhone subView animation: slide downiPhone subView 动画:向下滑动
【发布时间】:2012-04-24 17:32:36
【问题描述】:

我已经搜索了一段时间,但我想要的基本上是“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];

【问题讨论】:

    标签: iphone animation subview


    【解决方案1】:

    我认为您正在寻找:UIModalTransitionStyleCoverVertical

    Presentation Transition Styles
    Transition styles available when presenting view controllers.
    
    typedef enum {
            UIModalTransitionStyleCoverVertical = 0,
            UIModalTransitionStyleFlipHorizontal,
            UIModalTransitionStyleCrossDissolve,
            UIModalTransitionStylePartialCurl,
    } UIModalTransitionStyle;
    

    它从下到上呈现,然后在关闭时从上到下。要从上到下转换,您需要自己滚动,或者从下面的目标 vc 开始,并以模态方式呈现起始 vc。

    【讨论】:

    • 我用我尝试过的一些代码更新了我的问题......它不会按照我想要的方式工作
    【解决方案2】:

    试试这个代码

      -(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 应用程序。请参阅文档。

    【讨论】:

    • 我收到一些错误,说明 containerView 未声明(女巫不是),但我不知道用什么代替 containerView。
    【解决方案3】:

    我的粗俗回答:

    如果您将初始视图向下移动到 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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      • 2013-10-31
      • 1970-01-01
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      相关资源
      最近更新 更多