iOS多个控制器,如何仅改变某一个控制器view上导航栏的隐藏或透明度

发布于 2022-09-01 20:45:49 字数 30 浏览 28 评论 0

隐藏了一个控制器的导航栏,其余都变隐藏了。 。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大姐,你呐 2022-09-08 20:45:49

下面的这段代码是让整个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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文