加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – xcode – 如何将视图锁定为纵向模式,但仍允许一个视图

发布时间:2020-12-15 01:49:41 所属栏目:百科 来源:网络整理
导读:我遇到设备轮换问题.除了一个视图,我显示公司启动画面,我想将所有剩余的应用程序视图锁定到纵向显示.在项目设置中,支持的方向是Portrait和LandscapeLeft.在“公司飞溅”中它工作正常,无论我如何旋转设备,视图旋转都被锁定在LandscapeLeft中.在我将设备向左旋
我遇到设备轮换问题.除了一个视图,我显示公司启动画面,我想将所有剩余的应用程序视图锁定到纵向显示.在项目设置中,支持的方向是Portrait和LandscapeLeft.在“公司飞溅”中它工作正常,无论我如何旋转设备,视图旋转都被锁定在LandscapeLeft中.在我将设备向左旋转的所有其他视图中,视图会改变而不是保持纵向显示.这些方法甚至没有开火?如果我从项目中支持的方向中删除横向,则会拧紧“公司启动”视图.我尝试将shouldAutorotate更改为NO,但这没有帮助.试图通过 here发布的建议,但这没有帮助.如果我将以下代码放入我的AppDelegate.m,一切都被锁定为纵向模式,并且“公司启动”在访问时崩溃.

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

除了一个屏幕外,无论设备如何旋转,如何将视图锁定为纵向模式?

**来自’公司飞溅’视图的方法.再次,应该是这样的工作.

-(NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

**来自所有其他视图的方法,当我不希望它们旋转时,这些视图会旋转出来

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // IOS5 Only returning that it should rotate to potrait
    return (interfaceOrientation == UIDeviceOrientationPortrait);
}

-(BOOL)shouldAutorotate
{
    // forcing the rotate IOS6 Only
    return YES;
}

-(NSInteger)supportedInterfaceOrientations
{
    // return number or enum IOS6 Only
    return UIInterfaceOrientationMaskPortrait;
}

我想也许可能是因为UITabBarController是根控制器而我在ViewController中呢?这些方法甚至没有开火?

解决方法

将观察者添加到要旋转的视图的viewDidLoad方法,如下所示:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
 addObserver:self selector:@selector(orientationChanged:)
 name:UIDeviceOrientationDidChangeNotification
 object:[UIDevice currentDevice]];

然后根据orientationChanged方法中的横向视图设置视图,如下所示:

- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = [UIDevice currentDevice];
switch(device.orientation)
{
    case UIDeviceOrientationPortrait:

        break;
    case UIDeviceOrientationPortraitUpsideDown:

        break;
    case UIDeviceOrientationLandscapeLeft:

        break;
    case UIDeviceOrientationLandscapeRight:

        break;

    default:
        break;
  };
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读