change screen rotation of app extension in objective c

我的未来我决定 提交于 2019-12-23 20:18:07

问题


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


来源:https://stackoverflow.com/questions/26672728/change-screen-rotation-of-app-extension-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!