2013-08-23 61 views
0

我想从服务器上下载一张图片,并将其设置为iphone4s的全屏,我使用UIScreen *mainScreen = [UIScreen mainScreen];并使用此主屏幕来获取大小(960x640)。当应用程序启动时,我将代码插入AppDelegate。为什么我的UIScreen和UIWindow尺寸不匹配?

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

显示如何从'UIScreen'获得大小。尺寸应该是点(而不是像素),所以两者都应该是320x480。 – rmaddy

+0

使用'UIScreen bounds'来获取像'UIWindow'一样大小的点。 'UIScreenMode'以像素为单位。在这两个属性的文档中明确指出了这一点。 – rmaddy

回答

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

+0

'UIScreen'不会以像素为单位给出尺寸。 “UIScreen bounds”和“UIScreen applicationFrame”都是关键点。它是以像素为单位的'UIScreenMode'。这是一个重要的区别。 – rmaddy