【问题标题】:Navigation Controller is rendered over the view I navigated to导航控制器呈现在我导航到的视图上
【发布时间】:2013-08-29 04:09:05
【问题描述】:

你们有没有偶然发现这个问题?

基本上在 iOS 7 中,导航控制器是在我导航到的子视图上呈现的。

在 iOS 6 中,我导航到的视图包含在导航栏和页脚之间。在 iOS 7 中,子视图看起来像全屏呈现,位于导航栏和页脚下。结果用户看不到它。

这是我导航到子视图的方式

BRSMyListSubViewController *tagsInfoVC = [[BRSMyListSubViewController alloc] initWithCheckinsList:self.checkinsList
                                                                                selectedTag:[self tagByIndexPath:indexPath]];

[self.navigationController pushViewController:tagsInfoVC animated:YES];

这是我在viewDidLoad中初始化它的方式

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStyleBordered target:self action:@selector(settings:)];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStyleBordered target:self action:@selector(logout:)];

值得一提的是,子视图是在 XIB 中使用 Autolayout 定义的。这是我的 XIB 的来源:http://pastebin.com/6RR0zYu4

最后是它在 iOS 6 中的样子

在 iOS 7 中

有什么想法吗?

【问题讨论】:

    标签: ios cocoa-touch ios6 uinavigationcontroller ios7


    【解决方案1】:

    好吧,我想通了。

    在您的子视图中(在我的情况下为BRSMyListSubViewController),在viewDidLoad 中,您需要设置这两个之一

    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.automaticallyAdjustsScrollViewInsets = NO;
    

    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.extendedLayoutIncludesOpaqueBars = YES;
    

    有趣的是,在根视图控制器中,这些值分别设置为默认 UIRectEdgeAllNOYES,但其 tableView 不在导航栏和页脚下。

    我不知道为什么这么不合逻辑。

    同样奇怪的是,edgesForExtendedLayout 必须与其他两个属性之一混合,即使它显然是造成这种行为的原因。

    PS。对于那些想在 iOS 6 上运行它的人。用if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)包围代码

    【讨论】:

    • 感谢您的回答,对我很有帮助。
    • 非常感谢您的回答,拯救我的一天!
    • 它仅适用于 iOS7,如果您在运行 iOS6 的设备中运行应用程序,它会像 iOS7 SDK 属性一样给出异常
    • @UsmanAwan 当然会例外。这些属性在 6 中不存在 :) 您需要使用选择器进行检查。我更新了这个答案。
    • @ruslan 最好先进行方法检查,然后再进行系统版本检查。 if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])以防系统版和基础版不相符。
    【解决方案2】:

    如果您不介意有一个不透明的导航栏,那么最简单的解决方案可能是在创建导航控制器的视图控制器中执行此操作:

    self.navigationController.navigationBar.translucent = NO;
    

    然后框架的定位将采用与 iOS6 相同的行为,神奇地!

    【讨论】:

      猜你喜欢
      • 2021-01-03
      • 2014-05-11
      • 2013-09-06
      • 2023-03-17
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      相关资源
      最近更新 更多