在目标c中更改app扩展的屏幕旋转

在目标c中更改app扩展的屏幕旋转

本文介绍了在目标c中更改app扩展的屏幕旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何锁定旋转屏幕,我希望我的应用扩展程序仅处于纵向模式。
当我在照片中使用我的扩展时,我可以将屏幕旋转到横向。

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.

谢谢

推荐答案

您必须选择:

1-在项目中将横向和纵向设置为支持的界面方向,然后为每个ViewController,你将覆盖支持的界面方向;

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-在项目中只设置纵向模式,在你需要的ViewController中,你可以制作90度轮换

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

编辑:所以你可以这样做。将控制器设置为keyPath UIDeviceOrientationDidChangeNotification 的观察者。然后:

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

这篇关于在目标c中更改app扩展的屏幕旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 09:14