这是我的问题......
这种情况发生在:
切换状态栏可见性的按钮代码:
- (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。
在iOS 5上使用hacky解决方法,通过停止旋转填充空间来修复此问题。
- (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
。但是,使用它的替换:willRotateToInterfaceOrientation
也不起作用。有什么想法吗?
答案 0 :(得分:0)
切换状态栏后,再次设置self.view.frame。
答案 1 :(得分:0)
在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
}
答案 2 :(得分:0)
好的答案是在willRotateToInterfaceOrientation
上使用相同的黑客我曾经说过这在我的问题中不起作用,但我只是再试一次它就行了。
- (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];
});
}
}
答案 3 :(得分:0)
打电话后
dismissViewControllerAnimated
此方法,然后调用
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
出现此问题。
我打电话的时候 [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide]; 首先,没问题。