change screen rotation of app extension in objecti

2019-07-07 08:33发布

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条回答
贼婆χ
2楼-- · 2019-07-07 08:51

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);
        }
    }
}
查看更多
登录 后发表回答