<分区>
<分区>
注意:这个问题似乎发生在模态视图被关闭之后。
我正在子类化我的 UINavigationController
以使其在包含导航的 View 上无法旋转。这是代码的样子……非常简单。我刚刚将 Interface Builder 中的 UINavigationController
类设置为 NavViewController
:
#import "NavViewController.h"
@interface NavViewController ()
@end
@implementation NavViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
@end
问题是,这导致我的顶部栏位置在从模态视图返回时变得困惑。例如,这是我导航到 View 时的样子(仅供引用:顶部状态栏上的黑色内置于导航栏的背景图像中):
然后在带有导航栏的 View Controller 上,我调用此代码以从相册中获取图片:
- (IBAction)goToPhotoAlbum
{
UIImagePickerController *mypicker = [[UIImagePickerController alloc] init];
mypicker.delegate = self;
mypicker.allowsEditing = NO;
mypicker.wantsFullScreenLayout = YES;
mypicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:mypicker animated:YES completion:nil];
}
然后我驳回它:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
当 View 重新出现时,导航栏现在看起来像这样:
当我从我的 Nav 子类中注释掉以下代码时,就像这样,一切似乎再次正常工作并且条形图正确定位:
/*
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
*/
有人知道这是怎么回事吗?我该如何解决?
最佳答案
回答我自己的问题:
这实际上是 Navigation bar overlapped by status bar 的副本
解决方法是将子类中的代码更改为:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
return YES;
}
关于ios - 为什么我的 UINavigtionController 栏只有在我覆盖它时才会在 iOS 7 上错误定位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21919532/