2013-08-15 3 views
2

я следующий код в моей основной функции ViewController viewDidLoadКак установить ориентацию второго UIWindow

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 


nav = [[NavWithAutoRotateViewController alloc] initWithRootViewController:self]; 

[window addSubview:[nav view]]; 
[window makeKeyAndVisible]; 


[[self navigationController] setNavigationBarHidden:YES]; 

Мой Ipad приложение в настоящее время настроен для работы только в ландшафтном режиме, и я использую это новое окно чтобы показать документ quicklook и позволить навигационной панели предоставить кнопку «Назад» и сохранить параметры для документа. Основная проблема заключается в том, что новая ориентация UIWindow не соответствует моим основным приложениям UIWindow.

У меня есть пользовательский UINavigationController, называемый NavWithAutoRotateController, и вот код для этого контроллера.

-(id)init 
{ 
    if(self) 
    { 
//  _supportedInterfaceOrientatoin = UIInterfaceOrientationMaskLandscape; 
//  _orientation = UIInterfaceOrientationLandscapeLeft; 
    } 


    return self; 
} 
- (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. 
} 

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscapeLeft; 
} 


// Tell the system which initial orientation we want to have 
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 
+0

У меня такая же проблема, вам удалось ее решить? –

ответ

1

Регистрация для уведомления об изменениях в строке состояния кадра, который только называется (AFAIK) при изменении ориентации, а затем определить ориентацию вашего нового окна ..

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(appWillChangeStatusBarFrameNotification:) 
              name:UIApplicationWillChangeStatusBarFrameNotification 
              object:nil]; 
+4

Что делать, если ориентация уже пейзажа, когда этот вид загружается и загружается как портрет? – mattwallace

4

Я думаю, что у меня есть решение. Кажется, что проблема связана с присвоением UIViewControllerrootViewController в вашем дополнительном UIWindow.

Если вы предположили, что можете использовать тот же контроллер вида, что и ваш основной UIWindow, а затем добавить что-то в качестве подзадач нового UIWindow, есть проблемы с ориентацией.

Чтобы решить эту проблему, я сделал следующее:

UIWindow *newWindow = [[UIWindow alloc] initWithFrame: [UIApplication sharedApplication].keyWindow.frame]; 
newWindow.windowLevel = UIWindowLevelStatusBar+1; 
// You can use a view controller instantiated from a xib or storyboard here if you want. 
// Just don't use the view controller already set as a UIWindow's rootViewController. 
UIViewController *newViewController = [[UIViewController alloc] init]; 
newWindow.rootViewController = newViewController; 
[newWindow makeKeyAndVisible]; 
// Add something to the new UIWindow. Can use the new UIViewController's view: 
[newViewController.view addSubview: myContentView]; 
// Or could add it as subview of UIWindow: - either works. 
[newWindow addSubview: myContentView]; 

Действовать таким образом, кажется, решили все странные вопросы, связанные с вращением. Надеюсь, это поможет.

Смежные вопросы