2

My iOS application supports all orientations except PortraitUpsideDown. But in the application I have an view with preferences which I want it to only be shown in Portrait orientation. So whenever this view is shown, it is rotated if needed, to be in portrait mode. That means that user will rotate device in portrait mode also, to setup preferences, and then after closing this view interface should now have portrait orientation. The problem is, that after preferences view is hidden interface stays in landscape orientation, since I block autorotation after this view is shown. So after the view is hidden I want to manually update the interface to current device orientation. How can I do it?


self.view.hidden=NO; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; self.view.alpha=1.0; [UIView commitAnimations]; 

This code is called from the OptionsViewController after a LongPressGesture on its superview.

3 Answers 3

2

I created a UIViewController extension to force update of orientation of a controller, based on the solution presented by Marek R. Since the new versions of iOS, his solution does not work anymore. I post here my solution to force orientation update (in order to take into account supported orientation methods of controller) without having side visual effects. Hope it helps.

UIViewController *vc = [[UIViewController alloc]init]; [[vc view] setBackgroundColor:[UIColor clearColor]]; [vc setModalPresentationStyle:(UIModalPresentationOverFullScreen)]; [self presentViewController:vc animated:NO completion:^{ dispatch_async(dispatch_get_main_queue(), ^{ [vc dismissViewControllerAnimated:YES completion:completion]; }); }]; 
Sign up to request clarification or add additional context in comments.

Comments

0

All you have to do is add the following to the view controller you're using for your preferences.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } 

6 Comments

I've tried this already. But it doesn't seem to work since this view is a subview of the main view, which does support all orientations. So if my main view will autorotate, preference view will also rotate. Or do I misunderstand something?
So this view is a subview in your self.view in your viewcontroller? You only want this particular subview to rotate while other views remain static? Is that what you want?
No, I have a MainView which is controlled by MainViewController and an OptionsView which is a subview of MainView and is controlled by OptionsViewController. And I want the MainView to autorotate, but the OptionsView to stay static in portrait mode.
Can you please post the code showing how you are calling for the options view?
I don't quite understand what you mean by "calling for the options view". Do you mean how do I make it to show up? I don't understand which exactly code you're interested in. I have the view set up in IB. And it is a view property of corresponding OptionsViewController, from which I access the view.
|
0

Calling this workaround works for me:

-(void)forceOrientationUpdate { UIViewController *c = [[UIViewController alloc]init]; [self presentModalViewController:c animated:NO]; [self dismissModalViewControllerAnimated:NO]; [c release]; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.