为什么我的UIScreen和UIWindow大小不匹配?

时间:2013-08-23 06:45:00

标签: iphone ios objective-c

我想从服务器下载图片并将其设置为iphone4s的全屏,我使用UIScreen *mainScreen = [UIScreen mainScreen];并使用此主屏幕获取尺寸(960x640)。当应用程序启动时,我将代码插入AppDelegate。

if (im!=nil){
    UIImageView *splashScreen = [[UIImageView alloc] initWithImage:im];
    [self.window addSubview:splashScreen];
    [UIView animateWithDuration:3 animations:^{splashScreen.alpha = 0.99;}
                     completion:(void (^)(BOOL)) ^{
                         [splashScreen removeFromSuperview];
    }];
}

我注意到大小不正确,然后我注销了self.window的大小,发现窗口的大小是320x480。这是怎么发生的?

以下是我如何获得尺寸:

UIScreen *mainScreen = [UIScreen mainScreen];
UIScreenMode *ScreenMode = [mainScreen currentMode];
CGSize size = [ScreenMode size];
CGFloat screenWidth = size.width;
CGFloat screenHeight = size.height;

1 个答案:

答案 0 :(得分:1)

这是点和像素之间的差异。

UIScreen以像素为单位返回大小,但UIKit会处理点数。以下是关于此主题的一些Apple文档: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW15

相关问题