1

I have a strange bug in my app when my UI flow is as follows:

  1. The mainViewController is launched in Portrait orientation, and in turn it displays a LoginViewController with modalPresentationStyle set to UIModalPresentationFullScreen.

  2. I turn the loginViewController to landscape mode, enter credentials to login (the methods to authenticate the user are defined in the mainViewController).

  3. The loginViewController is dismissed (from the mainViewController) and a bunch of buttons are loaded onto the screen to indicate that it's the home screen.

Now my problem is that the button positions appear as if the app were in Portrait orientation even though the app was switched to Landscape while the loginViewController was presented.

Moreoever, this happens ONLY when the modalPresentationStyle is set to UIModalPresentationFullScreen! When I present it as a form sheet or a page sheet, everything works normally (I, however, need my loginViewController to be displayed FullScreen).

So far I've tried manually calling the shouldAutorotate method when the loginViewController is dismissed etc., and that solves the problem but seems like a shoddy workaround rather than a fix.

I've also tried calling the shouldAutorotate method of the mainViewController from the loginViewController, but this changes nothing.

Any ideas on how to fix the issue?

4

2 に答える 2

1

iOS 6では、自動回転が変更されました。iOS6shouldAutorotateToInterfaceOrientation:では、UIViewControllerのメソッドは非推奨になりました。代わりに、supportedInterfaceOrientations:andshouldAutorotateメソッドを使用する必要があります。

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;    
}

モーダルViewControllerは、iOS 6で回転呼び出しを受け取らなくなりましたwillRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:。およびdidRotateFromInterfaceOrientation:メソッドは、それ自体でフルスクリーンプレゼンテーションを行うView Controllerで呼び出されなくなりました。たとえば、次のように呼び出されますpresentViewController:animated:completion:

この回答では、iOS6での回転の変更についてさらに説明します


[編集]まったく別の方法は、ローテーションイベントに登録することです。利点は、だけでなく、すべてのオブジェクトがこれに登録できることですUIViewController。これは通常、ビューが読み込まれたときに実行され、ビューが消えたときに停止します(ここにdeallocを配置します)。セレクターのメソッドは、向きが変わると呼び出されます(ここではorientationChanged:):

- (void)viewDidLoad {
    [super viewDidLoad];
    // Start generating device rotations and register for them
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}

- (void)dealloc {
    // Deregister and stop generating device rotations
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
    [super dealloc];
}
于 2012-12-10T18:16:15.833 に答える
0
check this out.... may be this'll help...


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     return (interfaceOrientation == UIInterfaceOrientationPortrait |interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown| interfaceOrientation == UIInterfaceOrientationLandscapeLeft | interfaceOrientation == UIInterfaceOrientationLandscapeRight);

}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}

- (BOOL) shouldAutorotate
{
    return YES;
}
于 2012-12-14T04:52:35.670 に答える