0
votes

In my iOS 7/8 app, I have several viewcontrollers all of which should be portrait. I have a view controller which has a full screen view which will play video. I need this view to able to rotate depending on orientation of the phone. However the view controller that contains the video view is not allowed to rotate, reason being there are some other views sometimes overlaid above the full screen video view that are part of the viewcontroller and these should not be rotated.

So how can I rotate a single view and how do I get informed that the orientation of the device has changed. The usual [UIApplication sharedApplication].statusBarOrientation doesn't work as the viewcontroller itself does not rotate.

How to solve this problem.

Thanks

1
this is a recipe to be rejected by Apple! If you want try your lack you can do it like that: view.transform = CGAffineTransformMakeRotation(M_PI_2) - Marek R
so you want a single viewController's view to be rotated and the others not ?!! - M.Othman
Hi, that CGAffineTransformMakeRotation method seems to be the way to go! - tech74

1 Answers

0
votes

You can't rotate the screen forcefully. There is another way, in your case you have all the screens in Portrait, and you need a ViewController which can rotate both ways. You need to follow few steps described below.

See image for the settings you need to do in the Build Settings.

enter image description here

  1. Create a Custom Class of type UINavigationController say CustomNavController, then in the .m class add the following code.

    -(BOOL)shouldAutorotate{
    
        return YES; 
    }
    
    - (NSUInteger)supportedInterfaceOrientations{
    
         return UIInterfaceOrientationMaskAll; 
    }
    
  2. Present the video controller as Modal using the CustomNavController, like below

    VideoViewController *controller=[[VideoViewController alloc] initWithNibName:@"VideoViewController" bundle:nil]; 
    CustomNavController *nav=[[CustomNavController alloc] initWithRootViewController:controller]; 
    [self presentViewController:nav animated:YES completion:nil];
    nav.navigationBar.hidden=YES;
    

And it should work, the trick is to separate rotations.