你的位置:首页 > 软件开发 > 操作系统 > presentViewController: 如何不覆盖原先的 viewController界面

presentViewController: 如何不覆盖原先的 viewController界面

发布时间:2015-06-05 00:00:23
PresentViewController 如何不遮挡住原来的viewController界面呢?可能有时候会遇到这种需求,需要弹出一个功能比较独立的视图实现一些功能,但是却不想单纯添加一个View上去,想做成viewController的形式。那么本文就详细说明下如何实现 pr ...

presentViewController: 如何不覆盖原先的 viewController界面

PresentViewController 如何不遮挡住原来的viewController界面呢?

可能有时候会遇到这种需求,需要弹出一个功能比较独立的视图实现一些功能,但是却不想单纯添加一个View上去,想做成viewController的形式。那么本文就详细说明下如何实现 presentViewController并且不覆盖原先视图的解决方案。

 

具体源码请访问 http://www.cnblogs.com/sely-ios/p/4552134.html

UIViewController之间的底部的跳转机制,具体内容太多就不详细说明了, 不过苹果提供了自定义UIViewController之间跳转的一个Delegate,那就是UIViewControllerTransitioningDelegate,具体请参照XCode中此Protocol的介绍

那么iOS7之前就需要自定义UIViewControllerTransitioningDelegate以及UIViewControllerAnimatedTransitioning来完成我们的需求,iOS8之后苹果已经给出解决方案,只需要设置UIViewController 的 modalPresentationStyle 属性为 UIModalPresentationOverCurrentContext就可以轻松达到我们的要求。

 

具体如何实现呢?

这里我也参照了github上由Blanche Faur贡献的Demo https://github.com/hightech/iOS-7-Custom-ModalViewController-Transitions,很轻松就能达到想要的效果了,下面是跳转的代码

 

- (IBAction)presentViewController:(id)sender

{

    if (self.background)

    {

        [self.view bringSubviewToFront:self.background];

        self.background.hidden = NO;

        self.background.layer.opacity = 0.3;

    }

    

    UINavigationController *navi = [self.storyboard instantiateViewControllerWithIdentifier:@"ToViewControllerNavi"];

    ToViewController *toViewController = navi.viewControllers[0];

    [toViewController setHandler:^(){

        self.background.hidden = YES;

    }];

    

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0)

    {

        [navi setTransitioningDelegate:self.transDelegate];

        navi.modalPresentationStyle = UIModalPresentationCustom;

        [self presentViewController:navi animated:YES completion:nil];

    }

    else

    {

        toViewController.view.backgroundColor = [UIColor clearColor];

        navi.modalPresentationStyle = UIModalPresentationOverCurrentContext;

        [self presentViewController:navi animated:YES completion:nil];

    }

}

效果图如下

presentViewController: 如何不覆盖原先的 viewController界面   presentViewController: 如何不覆盖原先的 viewController界面


原标题:presentViewController: 如何不覆盖原先的 viewController界面

关键词:ie

ie
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。