Update interface orientation manually in iOS

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?

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView commitAnimations];

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


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];

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);

Calling this workaround works for me:

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

Need Your Help

How to use ORDER BY CHARINDEX() along with UNION?

sql sql-server