【问题标题】:emulate iOS7 controller push animation模拟 iOS7 控制器推送动画
【发布时间】:2013-09-27 08:13:34
【问题描述】:

到目前为止,我一直在使用来自this answer 的代码来模拟推送视图。但是现在视图推送动画发生了变化。有没有人有代码来模拟新的动画?

【问题讨论】:

    标签: iphone ios7 pushviewcontroller


    【解决方案1】:

    我找到了一种模拟它的方法,它非常接近原版。

    您必须添加 MTAnimation(这是指数级缓和所必需的)。该库需要QuartzCore,因此如果尚未添加,则必须将其添加到项目设置中“构建阶段”中的“链接库”中。

    这里是代码:

    推送控制器动画

    // Get the views
    UIView * fromView = sourceViewController.view;
    UIView * toView = destinationViewController.view;
    UIView *darkenView = [[UIView alloc] initWithFrame:fromView.frame];
    [darkenView setBackgroundColor:[UIColor colorWithRed:255 green:255 blue:255 alpha:0]];
    [fromView addSubview:darkenView];
    
    // Get the size of the view area.
    CGRect viewSize = fromView.frame;
    
    // Add the new view to the old view.
    [fromView.superview addSubview:toView];
    
    // Position the new view outside of the screen
    toView.frame = CGRectMake( viewSize.size.width , viewSize.origin.y, viewSize.size.width, viewSize.size.height);
    [UIView mt_animateViews:[NSArray arrayWithObjects:fromView, toView, nil]
                   duration:.55
             timingFunction:MTTimingFunctionEaseOutExpo
                    options:UIViewAnimationOptionAllowAnimatedContent
                 animations:
        ^{
            // Animate the replacing of the views 
            fromView.frame =CGRectMake( -(viewSize.size.width/3) , viewSize.origin.y, viewSize.size.width, viewSize.size.height);
            toView.frame =CGRectMake(0, viewSize.origin.y, viewSize.size.width, viewSize.size.height);
            [darkenView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.1]];
        }
                     completion:
        ^{
            // Remove the old view 
            [darkenView removeFromSuperview];
            [fromView removeFromSuperview];
        }];
    

    弹出控制器动画(如返回按钮)

    // Get the views.
    UIView * fromView = sourceViewController.view;
    UIView * toView = destinationViewController.view;
    
    // Get the size of the view area.
    CGRect viewSize = fromView.frame;
    
    // Add the new view to the old view.
    [fromView.superview insertSubview:toView belowSubview:fromView];
    
    // Position the new view outside of the screen
    toView.frame = CGRectMake( -(viewSize.size.width/3) , viewSize.origin.y, viewSize.size.width, viewSize.size.height);
    
    UIView *darkenView = [[UIView alloc] initWithFrame:toView.frame];
    [darkenView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.1]];
    [toView addSubview:darkenView];
    
    [UIView animateWithDuration:0.35 delay:0 options:UIViewAnimationOptionAllowAnimatedContent animations:
    ^{
             // Animate the replacing of the views 
             fromView.frame =CGRectMake(viewSize.size.width , viewSize.origin.y, viewSize.size.width, viewSize.size.height);
             toView.frame =CGRectMake(0, viewSize.origin.y, viewSize.size.width, viewSize.size.height);
             darkenView.frame = toView.frame;
             [darkenView setBackgroundColor:[UIColor colorWithRed:255 green:255 blue:255 alpha:0]];
    }
                     completion:^(BOOL finished)
    {
        if (finished)
        {
            // Remove the old view 
            [fromView removeFromSuperview];
            [darkenView removeFromSuperview];
        }
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-10
      • 1970-01-01
      • 1970-01-01
      • 2015-08-21
      • 1970-01-01
      • 2018-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多