Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

willRotateToInterfaceOrientation not being called from presented viewcontroller

I have uiviewcontroller on ipad with this configuration:

shouldAutorotate (true) supportedInterfaceOrientations (UIInterfaceOrientationMaskAll) and inside willRotateToInterfaceOrientation i perform some trick to adjust my interface.

From a child of this controller I show a QuickLookController with this -poor- code.

[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:previewController animated:YES completion:nil];

But if I rotate my ipad the method willRotateToInterfaceOrientation not being called, So I cannot do the trick to adjust the interface.

Someone can explain me or given me some advices? thanks

like image 629
IgnazioC Avatar asked Jan 05 '13 09:01

IgnazioC


2 Answers

Reason : There may be many possibilities to this problem.

1) If your view's viewController is a subView of some other rootViewController which is not a navigationController, then there might be chances that rotation call is not propagating to the subView's controller.

2) Somewhere I read that if Super methods are not called properly where it is needed then it might be the cause of rotation problem, which means that all ViewControllers in view stack which are related to the autorotation must call the super methods in method implementations (i.e. calling [super viewDidLoad] from the ViewController's viewDidLoad).

You can use below trick to handle orientation changes.

Register a notifier in viewWillAppear.

-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];}

The orientation change will notify the below function.

- (void)orientationChanged:(NSNotification *)notification{
[self handleOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}

which will call the below method where you can handle the orientation changes.

   - (void) handleOrientation:(UIInterfaceOrientation) orientation {

        if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
        { 
            //handle the portrait view    
        }
        else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
        {
            //handle the landscape view 
        }
     }
like image 155
Moin Ahmed Avatar answered Oct 31 '22 14:10

Moin Ahmed


I found a paragraph on apple documentation:

If your view controller’s contents are not onscreen when a rotation occurs, then it does not see the list of rotation messages. For example, consider the following sequence of events:

  • Your view controller presents another view controller’s contents full screen.
  • The user rotates the device so that the user interface orientation changes.
  • Your app dismisses the presented view controller.

In this example, the presenting view controller was not visible when the rotation occurred, so it does not receive any rotation events. Instead, when it reappears, its views are simply resized and positioned using the normal view layout process. If your layout code needs to know the current orientation of the device, it can read the app object’s statusBarOrientation property to determine the current orientation.

that say exactly what is my problem, so i add some logic inside -(void)viewWillAppear:(BOOL)animated to adjust my layout if something is'n in the right place.

like image 4
IgnazioC Avatar answered Oct 31 '22 16:10

IgnazioC