简体   繁体   English

iPhone中的锁定方向问题

[英]Locking orientation issue in iphone

I have a structure like this 我有这样的结构

LoginViewController-->Root

LoginViewController-->UINav---->HomeViewController

Now I have to lock this orientation to portrait only for iPhone and have to provide both orientations for iPad 现在,我必须将此方向锁定为仅适用于iPhone的肖像,并且必须同时为iPad提供两种方向

For the Login Controller, I wrote this 对于登录控制器,我写了这个

-(BOOL)shouldAutorotate{

    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
    {
        return YES;
    }
    else
    {
    return NO;
    }
}

This is working fine. 一切正常。 I got only a portrait orientation in iPhone and both portrait as well as landscape orientation in iPad 我在iPhone中只有纵向方向,在iPad中只有纵向和横向方向

But the same piece of code is written in HomeViewController is not working. 但是用HomeViewController编写的同一段代码无法正常工作。 Is it due to the Navigation Controller which is embedded with HomeViewConroller. 是由于HomeViewConroller内置了导航控制器。

Well. 好。 I got a fix for that myself. 我自己解决了这个问题。 Posting the solution on what to do as it might help others too. 将解决方案发布在做什么上可能会有所帮助。 Just uncheck the Device Orientation checks ( LandscapeLeft and LandscapeRight ) in Target->General 只需在Target-> General中取消选中Device Orientation检查( LandscapeLeftLandscapeRight

在此处输入图片说明

And write the same piece of code in every controller 并在每个控制器中编写相同的代码

-(BOOL)shouldAutorotate{

    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

This worked for me. 这对我有用。 Now I only get a portrait mode in iPhone and a landscape as well as a portrait mode in iPad. 现在,我只能在iPhone和风景模式中使用人像模式,而在iPad中只能使用人像模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM