Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么我的UIScreen和UIWindow大小不匹配?_Iphone_Ios_Objective C - Fatal编程技术网

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

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]

我想从服务器下载一张图片,并将其设置为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;

这就是点和像素之间的区别

UIScreen返回以像素为单位的大小,但UIKit处理点。以下是一些关于该主题的苹果文档:

显示如何从
ui屏幕获取尺寸。大小应以点(而不是像素)为单位,因此两者都应为320x480。使用
ui屏幕边界
获取以点为单位的大小,就像
ui窗口
一样
UIScreenMode
以像素为单位。文档中明确说明了这两个属性。
UIScreen
没有给出它的像素大小
UIScreen界限
UIScreen应用程序框架
都是点。以像素为单位的是
UIScreenMode
。这是一个重要的区别。