【问题标题】:Guide me on UIDevice currentDevice在 UIDevice currentDevice 上指导我
【发布时间】:2011-06-03 05:09:54
【问题描述】:

我正在使用以下代码来设置设备方向

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

当我使用时,我收到了警告,我找到了以下代码来修复该警告。

@interface UIDevice (MyPrivateNameThatAppleWouldNeverUseGoesHere)
- (void) setOrientation:(UIInterfaceOrientation)orientation;
@end

现在我想知道的是......

应用商店能否接受此代码进入应用程序?

感谢您的帮助!

【问题讨论】:

    标签: iphone iphone-sdk-3.0


    【解决方案1】:

    天哪,不。您收到的警告是因为这不是读写属性;仅添加一个声明该方法的类别不会让您设置方向。 AppStore 不仅不会接受这个,它会在第一次调用时崩溃,因为没有访问器。 (嗯,它很可能会崩溃。这里可能有一个未记录的 API,在这种情况下,您只会被拒绝)。

    【讨论】:

      【解决方案2】:

      如果您尝试以编程方式旋转视图,您应该查看shouldAutorotateToInterfaceOrientation,如果您只是希望应用程序具有特定方向,请尝试使用 plist 中设置的 UIInterfaceOrientation。

      另一个有用的帖子: Forcing UIInterfaceOrientation changes on iPhone

      【讨论】:

        【解决方案3】:

        不设置方向,正确的做法是让您的应用程序在用户旋转手机时进行监听,然后返回 YES 或 NO 以指示应用程序实际上应该旋转(即始终返回 NO如果您希望应用程序始终保持其初始状态。)每当用户改变方向时,都会自动调用 shouldAutorotateToInterfaceOrientation: 方法。

        例如,在您的视图控制器中,实现只允许手机在左右横向使用的方法:

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

        您还需要通过将 UIInterfaceOrientation 标记添加到应用的 info.plist 文件中并使用值 UIInterfaceOrientationLandscapeRight 来设置应用的默认方向(因此它不会以纵向模式启动)。否则,默认值为纵向,用户必须倾斜手机才能使其进入预期方向。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-10
          • 2013-01-02
          • 1970-01-01
          • 2011-01-28
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多