【问题标题】:Device orientation - change in legal way (iOS 4.0+)设备方向 - 以合法方式更改(iOS 4.0+)
【发布时间】:2011-11-08 23:26:14
【问题描述】:

我的应用程序有导航栏,其中第一个屏幕返回“是”方向,第二个屏幕根据用户在第一个屏幕中选择的内容设置为某个方向。从第 2 个屏幕返回第 1 个屏幕后,如果用户手持设备为纵向但界面为横向,则第 1 个屏幕设置为横向。发生这种情况是因为

(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation 

仅在更改设备方向后调用。

我想检查什么是设备方向 atm 并将界面方向设置为此。 试过了:

//1st method:
UIViewController *rotateTheScreen = [[UIViewController alloc]init];
[self presentModalViewController:rotateTheScreen animated:NO];
[self dismissModalViewControllerAnimated:NO];
[rotateTheScreen release];

//2nd method:
UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;

//3rd method:
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

第一个表现得很奇怪,除了从界面方向=横向和设备方向=横向返回之外,旋转所有情况(这是一个错误,他旋转到横向) 第二次检查界面,就像名字所说的那样,但对我的问题不起作用 据我所知,第三个是私有的,Apple 拒绝使用它的应用程序。

【问题讨论】:

    标签: iphone objective-c ios orientation


    【解决方案1】:

    看看这个thread。 基本上,没有办法强制设备方向让您的应用程序获得 Apple 的批准。

    简而言之,该方法存在,但它是UIDevice 类的未记录方法。

    [[UIDevice currentDevice] setOrientation: UIInterfaceOrientationLandscapeRight animated:YES];
    

    这会给出一个编译器警告,您可以使用一个类别来消除它。

    @interface UIDevice (MyAwesomeMethodsThatAppleWillNeverAllowMeToUse)
        -(void)setOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated;
        -(void)setOrientation:(UIInterfaceOrientation)orientation;
    @end
    

    另外,有人说您可以使用 performSelector 间接调用这些方法来绕过 Apple 的静态代码分析,您可以在 cmets here 中阅读。

    【讨论】:

      【解决方案2】:

      据我所知,没有合法的途径。如果我错了,请纠正我!

      【讨论】:

        【解决方案3】:

        更改项目 plist 文件中的“初始界面方向”

        【讨论】:

        • 这并不能解决问题,因为他想在应用启动后旋转屏幕。
        • 初始仅当您打开应用程序时,我的问题是我已经打开它并从不同的屏幕返回(我的问题的第 1 段)。此外,我需要将其设置为当前设备方向,而不是我想要的。
        • @Nekto 不是他,而是她 ;) 但是,就像您所说的那样,似乎没有合法的方法。感谢您的帮助!
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-09-20
        • 1970-01-01
        • 2023-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多