Swift 将 TabBar 放置在屏幕顶部在 iOS 11 中不起作用 [英] Swift Placing TabBar on top of the screen not working in iOS 11
问题描述
在 UITabBarController 中,我使用以下代码将标签栏放置在屏幕顶部:
In UITabBarController, I am placing the tab bar on top of the screen using below code :
self.tabBar.frame = CGRectMake(0,0,UIScreen.mainScreen().bounds.width,50)
这在 iOS 10 上完美运行.但是当在 iOS11 上安装相同的应用程序时.它只放在底部,不向上移动.
This works perfectly on iOS 10. But when the same app is installed on iOS11. It placing at the bottom only and not moving up.
真不知道iOS11有什么变化
但是
如何为 iOS 11 向上移动标签栏
Realy dont know what has changed in iOS11
But
How to move tabbar up for iOS 11
推荐答案
经过一番折腾终于找到了解决方案.
After so much struggle figured out the solution.
我将 tabBar.frame 代码放置在适用于 iOS 10 及更低版本的 viewDidAppear 中,但为了支持 iOS 11,需要放置在 viewDidLayoutSubviews 中,如下所示,这实际上是正确的方法:
I was placing the tabBar.frame code inside viewDidAppear which works for iOS 10 and below but to support for iOS 11, need to place inside viewDidLayoutSubviews as shown below which is actually the correct method :
override func viewDidLayoutSubviews()
{
tabBar.frame = CGRectMake(0,0,UIScreen.mainScreen().bounds.width,50)
}
这篇关于Swift 将 TabBar 放置在屏幕顶部在 iOS 11 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!