我一直在肖像模式下编写我的通用应用程序,现在大约15个笔尖文件,许多ViewCotnrollers之后,我想实现showerautorotateTotoInterfaceorientation,并在景观模式下设计一些屏幕。

添加:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return YES;
} 

对于我所有的ViewControllers,都不做这项工作。

在调试期间,我看到这种方法被称为,但它无法正常工作!不在模拟器中,不在设备中,而不是在iPhone中,而不是在iPad中!

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return (interfaceOrientation == UIInterfaceOrientationPortrait ||
   interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
   interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
   interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown );
} 

也没有工作

添加:

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

对于我的ViewDidload和ViewDidunload,也没有工作。

我迷路了..任何帮助都会做的!

只有一个信息...我所有的观点都是uicontrol类型,因为我需要Tuchupinside才能工作。

为您的帮助加油。

有帮助吗?

解决方案

确保您的所有父视图都具有utoresizessubviews =是。如果您没有在IB中为所有观点设置弹簧和支柱,则可能需要在代码中执行此操作。

引用接口构建器用户指南:

重要的是:在可可笔尖文件中,如果您在接口构建器中没有为您的视图设置任何弹簧或支撑杆,但是请使用setAutoresizingmask:在运行时添加自动化行为的方法,您的视图仍未显示正确的自动化行为。原因是,如果这些孩子没有弹簧和支柱,则接口构建器完全可以自动对父母视图的孩子自动化。要再次启用自动化行为,您必须将“是”传递给setAutoresizessubviews:父视图的方法。这样做后,孩子的观点应正确自动化。

其他几件事要注意:

  1. 只有在将其根视图控制器设置为自动座时,uInavigationController才会自动旋转。

  2. 仅当将其所有视图控制器设置为自动座时,uitabbarcontroller才能自动自动。

其他提示

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

您要建造哪个iOS?它在iOS 6.0中被弃用。 (您应该覆盖支持的接口方向和优先界面端口化方法。)

另外,您可以在UiviewController类上调用showerautotate:

https://developer.apple.com/library/ios/documentation/uikit/reference/uiviewcontroller_class/reference/reference/reference.html#/apple/apple_ref/apple_ref/occ/instm/uiviewiewconcontroller/shouldautoutatorate


确保您已经在项目设置的“夏季”选项卡中检查了支持的接口方向(在最顶部选择“项目导航器”中的项目名称)。

如果您没有选择要在此处使用的方向,则模拟器/iPhone将不允许屏幕更改方向。

我遇到了这个问题,但它在ios6中起作用,但ios5不起作用。事实证明,我在故事板上有一个视图,我尚未参加ViewController课程。

...最后但并非最不重要的一点是,请确保您没有在测试设备上激活设置“肖像方向锁定”(当然不适用于模拟器),无论如何,这都会禁用在任何应用程序中旋转 shouldAutorotateToInterfaceOrientation 返回。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top