Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
637 views
in Technique[技术] by (71.8m points)

ipad - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 
        }
     }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...