presentViewController: 如何不覆蓋原先的 viewController介面,uipageviewcontroller

來源:互聯網
上載者:User

presentViewController: 如何不覆蓋原先的 viewController介面,uipageviewcontroller

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

    }

}

如下

   

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.