1
所以我正在开发一个应用程序,顶部有UINavigationBar,底部有UITabBar。而且我很难弄清楚视图的真实可用高度。 我试着通过计算UINavigationBar高度和UITabBar高度来计算可用屏幕高度,并从主屏幕高度中减去它,但这仍然不是真正的大小。UINavigationBar + UITabBar可用屏幕高度
这里是我的失败,获得可用的屏幕高度代码:
CGRect screenRect = [[UIScreen mainScreen] bounds];
_screenHeight = screenRect.size.height;
CGFloat tabBarHeight = _rootViewController.tabBar.frame.size.height;
UINavigationController* navigatior = _rootViewController.viewControllers[0];
CGFloat navigationBarHeight = navigatior.navigationBar.frame.size.height;
CGFloat visibleHeight = _screenHeight - navigationBarHeight - tabBarHeight;
return visibleHeight;
有没有干净的方式知道在UINavigationBar的+ UITabBar基于应用程序的实际可用的屏幕尺寸?
我不使用故事板,我喜欢基于xib的应用程序x)。除此之外,我会像你说的那样使用自动布局,这在我的大部分视图控制器中都能很好地工作。除了这个,我有一个UIScrollView,所以我需要将内容大小设置为正确的高度。 :/ 感谢您的回应 – 6rod9