有一个定制的导航栏,并且在 iOS 9 之前一直完美运行。 横向模式下出现奇怪的边距。
使用标准代码来创建此布局。
- (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/