我升级到了新的 iPhone 并升级了我的应用程序。我在 x/xr/xs 布局中添加了,因此黑色边框现在消失了。
我的 View 顶部有一个导航栏,但现在它过多地进入状态栏?我该如何解决?以编程方式进行,而不是 Storyboard(学习代码)。
一些代码:
func buildTopbar()
{
statusbar = UIView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 20));
statusbar.backgroundColor = UIColor(red: 247/255, green: 247/255, blue: 247/255, alpha: 1.0);
navigationbar = UINavigationBar(frame: CGRect(x: 0, y: 20, width: self.view.bounds.width, height: 44));
navigationbar.barTintColor = UIColor(red: 247/255, green: 247/255, blue: 247/255, alpha: 1.0);
let texta = UIBarButtonItem(title: "A", style: .plain, target: self, action: #selector(settingToolbar(sender:)));
let textb = UIBarButtonItem(title: "B", style: .plain, target: self, action: #selector(inviteToolbar(sender:)));
texta.tintColor = ColorHelper.primaryColor();
textb.tintColor = ColorHelper.primaryColor();
...
navigationbar.setItems([title], animated: false);
self.view.addSubview(statusbar);
self.view.addSubview(navigationbar);
}
我将状态栏设置为 20,这与旧手机中的状态栏相同。
最佳答案
我建议创建一个 UINavigationController 并将您的 Controller 添加到该导航 Controller ,它将自动调整导航栏。
如果您想手动添加导航栏。 您必须将其框架 Y 位置设置正确。
计算导航栏的起始 Y 位置
let startingYPos = UIApplication.sharedApplication.statusBarFrame.size.height;
navigationbar = UINavigationBar(frame: CGRect(x: 0, y: startingYPos, width: self.view.bounds.width, height: 44));
关于ios - 将导航栏放置在安全区域顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53607039/