Iphone 为什么我的UIScreen和UIWindow大小不匹配?
我想从服务器下载一张图片,并将其设置为iphone4s的全屏,我使用Iphone 为什么我的UIScreen和UIWindow大小不匹配?,iphone,ios,objective-c,Iphone,Ios,Objective C,我想从服务器下载一张图片,并将其设置为iphone4s的全屏,我使用UIScreen*mainScreen=[UIScreen mainScreen]并使用此主屏幕获取大小(960x640)。当应用程序启动时,我将代码插入AppDelegate if (im!=nil){ UIImageView *splashScreen = [[UIImageView alloc] initWithImage:im]; [self.window addSubview:splashScreen]
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;
这就是点和像素之间的区别 UIScreen返回以像素为单位的大小,但UIKit处理点。以下是一些关于该主题的苹果文档:
显示如何从
ui屏幕获取尺寸。大小应以点(而不是像素)为单位,因此两者都应为320x480。使用ui屏幕边界
获取以点为单位的大小,就像ui窗口
一样UIScreenMode
以像素为单位。文档中明确说明了这两个属性。UIScreen
没有给出它的像素大小UIScreen界限
和UIScreen应用程序框架
都是点。以像素为单位的是UIScreenMode
。这是一个重要的区别。