3

How do I lock from rotating screen, I want my app extension to be only in portrait mode. When I'm using my extension inside Photos my I can rotate the screen to landscape.

thanks

user3182143
  • 9,459
  • 3
  • 32
  • 39
eskopium
  • 43
  • 5
  • I'm not sure, but I think that you app extension inherits your project settings. So lock there the screen and it will be locked everywhere – Iulian Popescu Oct 31 '14 at 11:02
  • False, project settings do not seem to affect app extension orientations. Regardless of what you have checked off, iOS seems to assume everything is a valid orientation by default. – Ruben Martinez Jr. Apr 02 '15 at 00:48

1 Answers1

3

You have to choice:

1- Set landscape and portrait as supported interface orientation in the project, and then for each ViewController, you will override the supported interface orientation;

2- Set only portrait mode in the project, and in the ViewController you need it, you can make a 90 degree rotation

self.view.transform = CGAffineTransformMakeRotation(M_PI_2);

EDIT: so you can do this. Set your controller as observer for the keyPath UIDeviceOrientationDidChangeNotification. Then:

-(void)changedOrientation: (NSNotification *)note
{
    if (note)
    {
        UIDevice *dev = (UIDevice *)note.object;
        if ([dev orientation] == UIInterfaceOrientationLandscapeRight)
        {
            self.view.transform = CGAffineTransformMakeRotation(M_PI_2);
        }
        else if ([dev orientation] == UIInterfaceOrientationPortrait)
        {
            self.view.transform = CGAffineTransformIdentity;
        }
        else if ([dev orientation] == UIInterfaceOrientationPortraitUpsideDown)
        {
            self.view.transform = CGAffineTransformIdentity;
        }
        else if ([dev orientation] == UIInterfaceOrientationLandscapeLeft)
        {
            self.view.transform = CGAffineTransformMakeRotation(-M_PI_2);
        }
    }
}
Luca D'Alberti
  • 4,749
  • 3
  • 25
  • 45