开发者

Ipad orientation problem with modal view

i've a problem with a modal view rotation. I create a main view in portrait mode, then i create a modal view. Everything works fine: i can rotate the modal view and all orientation 开发者_如何学运维are supported. If i create the main view in portrait mode then rotate in landscape and after that i create my modal view... the modal is in portrait mode and not in landscape as it should be.

Both shouldAutorotateToInterfaceOrientation in main view and modal view return YES.

Any ideas?


This can happen if the view controller is being presented after iOS queues a rotate event, but before the rotate event is handled. From observation, I think rotate events are specific to the view controllers currently being presented.

This is a helpful way of thinking of it:

  1. The rotate event is queued up by iOS for the top view controller, A.
  2. Your code presents a view controller, B.
  3. The rotate event is dequeued, but it addresses only view controller A.

Thankfully, there's a really easy fix. Just assume there's a rotate event in the event queue, and make sure your view is actually presented after it. You do this by queuing the presentation of your new view controller, rather than presenting it directly. Blocks queued to the main queue will be executed after any events already queued (like rotate events) but before the user gets a chance to interact with your UI.

Change:

[self performSegueWithIdentifier: @"firstRun" sender: self];

To:

dispatch_async(dispatch_get_main_queue(), ^{
    [self performSegueWithIdentifier: @"firstRun" sender: self];
});

After doing this, you get this behaviour instead:

  1. The rotate event is queued up by iOS for the top view controller, A.
  2. Your code schedules the block that will present the new view controller.
  3. The rotate event is dequeued, but it addresses only view controller A.
  4. The new view controller, B, is presented by your block. It gets the new orientation.


I had the same issue. I finally worked around it by displaying the modal view from my main view controller (and not from a view controllers of one of the subviews).


Had the same issue, finaly fixed delaying the modal for a second, so the 'parent' view controller could get the correct orientation.

[self performSelector:@selector(presentLogin) withObject:nil afterDelay:1.0]

presentLogin looks like:

- (void) presentLogin {
LoginVC *loginVC = [[LoginVC alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginViewController];
nav.modalPresentationStyle =UIModalPresentationFormSheet;
[self presentViewController:nav animated:YES completion:NULL]; 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜