0

I want to download a picture from the server and set it as fullscreen for the iphone4s, i use UIScreen *mainScreen = [UIScreen mainScreen]; and use this mainscreen to get the size (it's 960x640). When the app launches, I insert the code to 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. 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;
Peter Walser
  • 15,208
  • 4
  • 51
  • 78
yudun1989
  • 996
  • 9
  • 23
  • 1
    Show how you get the size from the `UIScreen`. Sizes should be in points (not pixels) so both should be 320x480. – rmaddy Aug 23 '13 at 06:47
  • Use `UIScreen bounds` to get the size in points just like `UIWindow`. `UIScreenMode` is in pixels. This is clearly stated in the docs for the two properties. – rmaddy Aug 23 '13 at 15:32

1 Answers1

1

That's the difference between points and pixels.

The UIScreen returns the size in pixels, however UIKit deals with points. 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

Bart van Kuik
  • 4,704
  • 1
  • 33
  • 57
  • `UIScreen` does not give it's size in pixels. `UIScreen bounds` and `UIScreen applicationFrame` are both in points. It is the `UIScreenMode` that is in pixels. This is an important difference. – rmaddy Aug 23 '13 at 15:31