首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >shouldAutorotateToInterfaceOrientation不工作

shouldAutorotateToInterfaceOrientation不工作
EN

Stack Overflow用户
提问于 2010-05-20 02:07:22
回答 3查看 35.9K关注 0票数 18

我一直在纵向模式下编写我的通用应用程序,现在在完成了大约15个nib文件,许多viewCotnrollers之后,我想实现shouldAutorotateToInterfaceOrientation并在横向模式下设计一些屏幕。

添加:

代码语言:javascript
复制
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return YES;
} 

到我所有的viewControllers,都做不到这项工作。

在Debug期间,我看到这个方法被调用了,但是它就是不能工作!不在模拟器中,不在设备中,不在Iphone中,不在Ipad中!

我在论坛上搜索了一些答案,看到了一些可以使用的建议:

代码语言:javascript
复制
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return (interfaceOrientation == UIInterfaceOrientationPortrait ||
   interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
   interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
   interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown );
} 

也不管用,

添加:

代码语言:javascript
复制
 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

代码语言:javascript
复制
 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

到我的viewDidLoad和viewDidUnload分别也不起作用。

我迷路了。任何帮助都可以!

还有一个信息..。我所有的视图都是UIControl类型的,因为我需要TuchUpInside才能工作。

感谢您的帮助。

EN

回答 3

Stack Overflow用户

发布于 2012-05-15 15:48:15

代码语言:javascript
复制
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    UIInterfaceOrientation des=self.interfaceOrientation;

    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) //iPad
    {
        if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown)//ipad-portairait
        {

        }
        else//ipad -landscape
        {

        }
    }
    else//iphone
    {
        UIInterfaceOrientation des=self.interfaceOrientation;

        if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown) //iphone portrait
        {

        }
        else //iphone -landscape
        {

        }
    }
return YES;
}
票数 2
EN

Stack Overflow用户

发布于 2012-10-18 05:15:31

我遇到了这个问题,但它在iOS6中有效,但在iOS5中不起作用。事实证明,我的故事板中有一个视图,我还没有创建一个视图控制器类。

票数 0
EN

Stack Overflow用户

发布于 2012-11-13 05:17:38

...and最后但并非最不重要的一点是,请确保您尚未激活测试设备上的“纵向锁定”设置(当然不适用于模拟器),这将禁止在任何应用程序中旋转,无论shouldAutorotateToInterfaceOrientation返回什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2868132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档