Iphone 如何停止iOS6中覆盖导航栏的状态栏
这是我的问题 这种情况发生在:Iphone 如何停止iOS6中覆盖导航栏的状态栏,iphone,ios,cocoa-touch,Iphone,Ios,Cocoa Touch,这是我的问题 这种情况发生在: 状态栏将使用按钮淡出 从横向旋转180度至倒置横向 使用该按钮,状态栏将淡入淡出状态。-它现在覆盖了导航栏 切换状态栏可见性的按钮代码: - (IBAction)toggleBar:(id)sender { NSLog(@"View Frame : %@", NSStringFromCGRect(self.view.frame)); // Toggle status bar visiblity BOOL isStatusBarHidde
- (IBAction)toggleBar:(id)sender
{
NSLog(@"View Frame : %@", NSStringFromCGRect(self.view.frame));
// Toggle status bar visiblity
BOOL isStatusBarHidden = [[UIApplication sharedApplication] isStatusBarHidden];
[[UIApplication sharedApplication] setStatusBarHidden:!isStatusBarHidden
withAnimation:UIStatusBarAnimationFade];
}
视图始终报告其帧为480 x 288
这个问题在iOS5上可以通过一个黑客的解决方法解决,即停止填充空间的旋转
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIApplication sharedApplication] isStatusBarHidden])
{
float oldAlpha = self.navigationController.navigationBar.alpha;
self.navigationController.navigationBar.alpha = 0.01;
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
double delayInSeconds = 0.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
self.navigationController.navigationBar.alpha = oldAlpha;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
});
}
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
这在iOS 6上不起作用,因为未调用
shouldAutorotateToInterfaceOrientation
。但是,使用它的替换:将旋转接口定向
也不起作用。有什么想法吗?切换状态栏后,再次设置self.view.frame。在IOS6上,您应该使用这些方法。看看这些
- (BOOL)shouldAutorotate
{
//returns true if want to allow orientation change
return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations
{
//decide number of origination tob supported by Viewcontroller.
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//from here you Should try to Preferred orientation for ViewController
}
好的,答案是在willRotateToInterfaceOrientation上使用相同的hack,我在我的问题中说过这不起作用,但我只是再次尝试,它成功了
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if ([[UIApplication sharedApplication] isStatusBarHidden])
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
double delayInSeconds = 0.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
});
}
}
我打电话之后
解雇可视控制器
此方法,然后调用
[[UIApplication sharedApplication]设置StatusBarHidden:NO with Animation:UIStatusBaranimation幻灯片]
这个问题出现了
当我打电话时
[[UIApplication sharedApplication]设置StatusBarHidden:NO with Animation:UIStatusBaranimation幻灯片];
首先,没问题。这不起作用。帧始终报告为480 x 268(旋转/切换状态栏之前/之后)。设置帧没有效果。谢谢你的回答。你检查过我的另一个解决方案吗?
的替代品应该是AutorotateTointerFaceOrientation
,而不是willRotateToInterfaceOrientation
。它是支持的接口方向@rmaddy同意的,但在ios 5中它有另一个目的-让你知道它将要旋转屏幕。这不是真的。调用shouldAutorotateToInterfaceOrientation
绝不表示视图控制器即将旋转。其目的是询问是否允许某些旋转。willRotateToInterfaceOrientation
方法用于指示实际即将发生旋转。记住,这些方法是关于视图控制器的,而不是关于屏幕的。@rmaddy-好的,显然你是对的willRotateToInterfaceOrientation
在iOS 5上也被调用。我认为这是iOS 6的一种新方法。willRotateToInterfaceOrientation
从iOS 2.0开始就存在了。