Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 是否应自动旋转指针面方向不';行不通_Iphone_Xcode_Ipad_Uiviewcontroller_Screen Orientation - Fatal编程技术网

Iphone 是否应自动旋转指针面方向不';行不通

Iphone 是否应自动旋转指针面方向不';行不通,iphone,xcode,ipad,uiviewcontroller,screen-orientation,Iphone,Xcode,Ipad,Uiviewcontroller,Screen Orientation,我一直在以肖像模式编写我的通用应用程序, 现在,在大约15个nib文件之后,许多ViewCotnroller, 我想实现shouldAutorotateToInterfaceOrientation,并在横向模式下设计一些屏幕 添加: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } 对于我的所有ViewController,不

我一直在以肖像模式编写我的通用应用程序, 现在,在大约15个nib文件之后,许多ViewCotnroller, 我想实现shouldAutorotateToInterfaceOrientation,并在横向模式下设计一些屏幕

添加:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return YES;
} 
对于我的所有ViewController,不执行此操作

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

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

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

添加:

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

对于我的viewDidLoad和viewDidUnload分别也不起作用

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

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


感谢您的帮助。

确保您的所有父视图都具有AutoResizesSubView=YES。如果尚未在IB中为所有视图设置springs和struts,则可能需要在代码中执行此操作

引用Interface Builder用户指南:

重要提示:在Cocoa nib文件中,如果 不要为其设置任何弹簧或支柱 您在Interface Builder中的视图 然后使用setAutoresizingMask: 方法添加自动调整大小行为 运行时,您的视图可能仍然不可用 显示正确的自动调整大小 行为。原因是这个接口 生成器禁用自动调整文件大小 父视图的所有子视图,如果 那些孩子没有弹簧和弹簧 支柱设置。要启用自动调整大小 再次,您必须将“是”传递给 setAutoresizesSubviews:方法 父视图。在这样做之后 子视图应正确自动调整大小

还有几件事需要注意:

  • UINavigationController只有在其根视图控制器也设置为自动旋转时才会自动旋转


  • UITabBarController只有在其所有视图控制器都设置为自动旋转时才会自动旋转


  • 我有这个问题,但它在iOS6中有效,但在iOS5中无效。事实证明,我的故事板中有一个视图,我还没有创建viewcontroller类。

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

    您为哪个iOS构建?它在iOS 6.0中被弃用。(您应该替代支持的InterfaceOrientations和preferredInterfaceOrientationForPresentation方法。)

    还可以在UIViewController类上调用shouldAutorotate:


    确保已在项目设置的“Summy”选项卡中检查支持的界面方向(在顶部的“项目导航器”中选择项目名称)


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

    您在哪些设备和/或模拟器版本上看到此情况?根导航或选项卡栏控制器的类型是什么?Xcode 3.2.2、iphone simulator 3.1.3(ipad 3.2)以及使用设备3.1.3。我的主窗口Nib文件中有选项卡栏和导航控制器。但是我的所有类都是UIViewController的子类“一个UIAbbarController只有在其所有视图控制器都设置为自动旋转时才会自动旋转。”---每次都会得到我;对于苹果来说,这是实现API的错误方式。希望有一天他们能解决这个问题。+1这将向任何使用nav和TabbarController制作“普通应用程序”的人简要而完整地解释自定义行为,这对我来说是可行的。作为补充说明,在IB中的选项卡栏中使用NavController构建的应用程序将获得正确的rootcontroller,并且在创建ViewController时默认的struts、autosize和视图方向设置都很好,因此无需设置或更正任何这些设置。“只有当其所有视图控制器都设置为自动旋转时,UITabBarController才会自动旋转。”!!(重复:)。似乎iOS 6及以上版本不是这样,但iOS 5是这样(对此行为感到非常困惑)。
     [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
    
    - (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;
    }