我有一个ViewController
在UINavigationcontroller
中,但导航栏是隐藏的。当我在iOS 7上运行应用程序时,状态栏显示在我的视图顶部。有没有办法避免这种情况?
我不想写任何特定于操作系统的代码。
我尝试将 View controller-based status bar appearance
设置为NO
,但没有解决问题。
我有一个ViewController
在UINavigationcontroller
中,但导航栏是隐藏的。当我在iOS 7上运行应用程序时,状态栏显示在我的视图顶部。有没有办法避免这种情况?
我不想写任何特定于操作系统的代码。
我尝试将 View controller-based status bar appearance
设置为NO
,但没有解决问题。
// 7.0 and above
#define IS_DEVICE_RUNNING_IOS_7_AND_ABOVE() ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
// 6.0, 6.0.x, 6.1, 6.1.x
#define IS_DEVICE_RUNNING_IOS_6_OR_BELOW() ([[[UIDevice currentDevice] systemVersion] compare:@"6.2" options:NSNumericSearch] != NSOrderedDescending)
将这些宏添加到您项目的prefix.pch文件中,可以在任何地方访问
if(IS_DEVICE_RUNNING_IOS_7_AND_ABOVE())
{
//some iOS 7 stuff
self.edgesForExtendedLayout = UIRectEdgeNone;
}
if(IS_DEVICE_RUNNING_IOS_6_OR_BELOW())
{
// some old iOS stuff
}
tableviewcontroller
时,automaticallyAdjustsScrollViewInsets=YES
和set self.edgesForExtendedLayout = UIRectEdgeNone
对我有用。在从YTPlayer的横向视图返回后,我的状态栏和导航栏重叠了。尝试了@comonitos版本但在我的iOS 8上无法工作,这是我的解决方案。
- (void)fixNavigationBarPosition {
if (self.navigationController) {
CGRect frame = self.navigationController.navigationBar.frame;
if (frame.origin.y != 20.f) {
frame.origin.y = 20.f;
self.navigationController.navigationBar.frame = frame;
}
}
}
每当您想要固定导航栏的位置时,只需调用此函数。我在YTPlayerViewDelegate的playerView:didChangeToState:
中进行了调用。
- (void)playerView:(YTPlayerView *)playerView didChangeToState:(YTPlayerState)state {
switch (state) {
case kYTPlayerStatePaused:
case kYTPlayerStateEnded:
[self fixNavigationBarPosition];
break;
default:
}
}
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
}