iPad的定位不仅仅是iOS中的四个

时间:2013-09-07 14:27:38

标签: ipad cocoa-touch ios5 orientation uitextview

现在我意识到我只为iPad版本编写应用程序。

我的iPad iOS版本是iOS 5.1

是的,我需要在加载数据之前检查iPad方向。

所以我查看以下代码。

if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
    {
        self.originalLandScape = CGRectMake(0, 48, 1024, 704);
        self.originalPortrait = CGRectMake(0, 48, 768, 960);

        self.txtView.frame = self.originalLandScape;
    }

    else
    {
        self.originalPortrait = CGRectMake(0, 48, 768, 960);
        self.originalLandScape = CGRectMake(0, 48, 1024, 704);

        self.txtView.frame = self.originalPortrait;
    }

因为我需要将修复大小设置为UITextView

然而我意识到当我的iPad使用横向并水平放下时,设置UITextView尺寸是不正确的。

但是,当我从地板上取下我的iPad并且手持Landscape之类的阅读书时,我的上述代码就可以了。

这两者之间有什么不同吗?

我不知道如何解决它。

感谢您的任何建议和帮助。

1 个答案:

答案 0 :(得分:1)

你是对的 - iPad方向不仅仅是四个,它是六个:

 UIDeviceOrientationLandscapeLeft
 UIDeviceOrientationLandscapeRight
 UIDeviceOrientationPortrait
 UIDeviceOrientationPortraitUpsideDown
 UIDeviceOrientationFaceUp
 UIDeviceOrientationFaceDown

因此,您的else条款不仅适用于人像方向,也适用于FaceUp和FaceDown。

我怀疑你真正想要使用的是接口方向。这可能与设备方向相同或不同(取决于应用程序支持的方向) - 但如果要为特定方向正确绘制UI元素,则它将是重要的界面的其余部分,而不是设备方向。

只有四种界面方向:

UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown

您可以使用UIViewController属性interfaceOrientation获取这些内容并使用UIKit函数UIInterfaceOrientationIsLandscape()UIInterfaceOrientationIsPortrait()

进行检查

在您的代码中尝试此操作

if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))) {
   ...
} else {
   ... 
}