简体   繁体   English

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

[英]Why does my UIScreen and UIWindow size not match?

I want to download a picture from the server and set it as fullscreen for the iphone4s, i use UIScreen *mainScreen = [UIScreen mainScreen]; 我想从服务器下载图片并将其设置为iphone4s的全屏,我使用UIScreen *mainScreen = [UIScreen mainScreen]; and use this mainscreen to get the size (it's 960x640). 并使用该主屏幕获取尺寸(为960x640)。 When the app launches, I insert the code to AppDelegate . 应用启动时,我将代码插入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];
    }];
}

I noticed the size is incorrect, then I logged out the size of the self.window and found the size of the window is 320x480. 我注意到大小不正确,然后我注销了self.window的大小,发现窗口的大小为320x480。 How did this happen? 这怎么发生的?

Here is how i get the sizes: 这是我得到尺寸的方法:

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

That's the difference between points and pixels. 那就是点和像素之间的差异。

The UIScreen returns the size in pixels, however UIKit deals with points. UIScreen返回以像素为单位的大小,但是UIKit处理点。 Here's some Apple documentation on the subject: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW15 这是有关此主题的一些Apple文档: https : //developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW15

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么UIScreen的大小是iPhone本身的一半(以像素为单位)? - Why is the size of my UIScreen half the size of the iPhone itself(in pixels)? 为什么[[UIApplication sharedApplication] 委托].window.bound ≠ [[UIScreen mainScreen] bounds].size - why does[[UIApplication sharedApplication] delegate].window.bound ≠ [[UIScreen mainScreen] bounds].size 在iOS上,我们可以从UIScreen对象获取主UIWindow对象吗? - On iOS, can we get to the main UIWindow object from the UIScreen object? 使用UIScreen驱动VGA显示-似乎不显示UIWindow吗? - Using UIScreen to drive a VGA display - doesn't seem to show the UIWindow? 为什么在XCode 7 iPhone 6 plus模拟器的[UIScreen mainScreen]尺寸和比例中,真实设备会返回不同的值? - Why in XCode 7 iPhone 6 plus simulator's [UIScreen mainScreen] size and scale return different value with real devce? 为什么OCMock与我的选择器不匹配? - Why does OCMock not match my selector? UIScreen是否有屏幕通知? - Does UIScreen have a notification for screen on? UIScreen MainScreen 边界返回错误的大小 - UIScreen MainScreen Bounds returning wrong size 无法更改UIWindow的大小 - Can't change the size of a UIWindow 在IOS 7的UIViewController的loadView方法中创建视图时,为什么UIScreen的mainApplication框架从状态栏下方开始? - When creating a view in IOS 7's loadView method of UIViewController, why does UIScreen's mainApplication frame begin beneath status bar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM