change screen rotation of app extension in objecti

2019-07-07 08:10发布

问题:

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

回答1:

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