iOS 9 : Unwanted margin in UINavigationBar landscape

标签 ios uinavigationbar margin uibarbuttonitem ios9

有一个定制的导航栏,并且在 iOS 9 之前一直完美运行。 横向模式下出现奇怪的边距。

enter image description here

使用标准代码来创建此布局。

- (UIBarButtonItem*)leftMenuButton {
    UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [menuBtn setImage:[UIImage imageNamed:@"menu_button.png"] forState:UIControlStateNormal];

    UIView *backArea = [[UIView alloc] initWithFrame:CGRectMake(0, 0, menuBtn.frame.size.width, menuBtn.frame.size.height)];
    [backArea addSubview:menuBtn];

//layer border are enabled just for issue visualization    
    backArea.layer.borderColor = [UIColor redColor].CGColor;
    backArea.layer.borderWidth = 1;
    menuBtn.layer.borderColor = [UIColor greenColor].CGColor;
    menuBtn.layer.borderWidth = 2;

    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backArea];
    return backItem;
}

最佳答案

我也刚刚偶然发现了这一点。当设备处于横向模式时,iOS 9 中的导航栏内容未对齐。看起来栏内容的定位使其适合 Compact 指标,即使栏仍然使用 Default 指标(例如在 UINavigationController 外部使用时) )。看起来条形图以某种方式与屏幕方向耦合。真是一团糟。

编辑:打开雷达#23027275。

关于iOS 9 : Unwanted margin in UINavigationBar landscape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32865192/

相关文章:

iphone - 使用字符串 "Settings"设置 Controller 标题不起作用

matplotlib - Matplotlib 中带有边缘 KDE 图和多个类别的散点图

css - 为什么 margin-right 不起作用,而 margin-left、margin-top 和 margin-bottom 却起作用?

ios - 如何更改导航栏字体

ios - Swift - 自定义 UIDatePicker 格式

objective-c - 将对象 ( UIViewController ) 转换到它们未知的子类

ios - 如何在Swift 2.2中检查3G,4G和wifi互联网连接

ios - 如何在使用 UIPageViewController 时将 UIBarButtonItem 添加到 NavigationBar

html - 当我给子 div 留出边距时,父 div 的背景会移动

ios - 为什么我的 sqlite 数据库在对核心数据模型进行版本控制时没有迁移?