簡體   English   中英

模擬iOS7控制器推送動畫

[英]emulate iOS7 controller push animation

到目前為止,我一直在使用此答案中的代碼來模擬推送視圖。 但是現在推動動畫的視圖發生了變化。 有人有模擬新動畫的代碼嗎?

我找到了一種模擬它的方法,它非常接近原始方法。

您必須添加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];
    }
}];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM