navigationbar - iOS多个控制器,如何仅改变某一个控制器view上导航栏的隐藏或透明度
大家讲道理
大家讲道理 2017-04-17 16:38:01
[iOS讨论组]
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(1)
PHPz

下面的这段代码是让整个ViewController都成为半透明的(也可以设置成不透明),没有导航栏。当从 Controller A 跳转到 Controller B 时,从效果看上去,B就像一个View一样,盖在了A上面。

B

// Present transparent UIViewController over UIViewController
// http://stackoverflow.com/questions/11236367/display-clearcolor-uiviewcontroller-over-uiviewcontroller
// vc.viewDidAppear not getting called, caused by pushViewController:vc, you should not both call presentViewController and pushViewController.
// http://stackoverflow.com/questions/14274706/presentviewcontroller-and-viewdidappear-not-getting-called-in-ios5-1-6
// https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

// @didPresentingVC : the view controller that did the presenting
+ (void)presentedFromViewController:(UIViewController *)didPresentingVC {
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:kStoryboardName bundle:nil];
    //@presentedVC: the view controller that was presented
    // kStroyboardIdB 定义在storyboard, Identity Inspector,
    UIViewController *presentedVC = [mainStoryboard instantiateViewControllerWithIdentifier:kStroyboardIdB];
    // 清除背景色
    presentedVC.view.backgroundColor = [UIColor clearColor];
    // 设置透明度
    presentedVC.view.alpha = 0.5;
    // fix bug that view not transparent on iOS version greater than 8.0 http://stackoverflow.com/a/26387371
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
        presentedVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    } else {
        didPresentingVC.modalPresentationStyle = UIModalPresentationCurrentContext;
        didPresentingVC.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
    }
    [didPresentingVC presentViewController:presentedVC animated:YES completion:nil];
}

然后在另一个ViewController A中调用这个方法,就调出了 Controller B:

A

- (void)OnClick {
    [B presentedFromViewController:self];
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号