IPhone Retina simulator has incorrect screen resolution

I am trying to write a universal application. The display should be slightly different for different screen resolutions. But when I code like this:

- (void)viewDidLoad {
    SCREEN_WIDTH=[[UIScreen mainScreen] applicationFrame].size.width;
    SCREEN_HEIGHT=[[UIScreen mainScreen] applicationFrame].size.height;
    NSLog(@"w:%f h:%f",SCREEN_WIDTH,SCREEN_HEIGHT);
...
}

I get the conclusion: w:320.000000 h:480.000000even if the simulator is set to
Hardware-> Device-> iPhone (Retina).
In addition, images with this resolution are displayed as full-screen images in the simulator.
I understand what I should receive w:640.000000 h:960.000000.
Is this true for anyone else? And any ideas why / how to fix it? See the related thread: here

+3
source share
3 answers

Here is what I learned. Since iOS4,

[[UIScreen mainScreen] applicationFrame].size.width; and

[[UIScreen mainScreen] applicationFrame].size.height;

"", "". = , iPhone4 4 . iPhone4, . , iPhone4 iPhone .

"" "-res", iPhone, ".png" "@2x.png" ( , ) . , .
, "img.png" , iPhone4 "img@2x.png", .

, / , .

"". . , -, , Wi-Fi - , "" ( " ".

, . , , iPhone4 , . , :

UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100.0, 50.0)];
[indicatorButton setBackgroundImage:
   [UIImage imageNamed:@"buttonImage.png"] forState:UIControlStateNormal];

, buttonImage.png - 200x100, . , 640x960 () , iPad, 320x480 , - :

+ (UIImage*)imageWithImage:(UIImage*)image newX:(float)newX newY:(float)newY{
    CGSize newSize=CGSizeMake((CGFloat)newX, (CGFloat)newY);
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0,0,newX,newY)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

iPhone4. . , - :

UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100.0, 50.0)];
    [indicatorButton setBackgroundImage:
       [Utilities imageWithImage:[UIImage imageNamed:@"buttonImage.png"] newX:100 newY:50] forState:UIControlStateNormal];

, "" iPhone4.

, , iPhone4 ( , ), :

+(bool)imAnIphone4{
    return([[UIScreen mainScreen]respondsToSelector:@selector(scale)] && [UIScreen mainScreen].scale==2);
}
+3

UIScreen Retina , . . UIScreen scale, :

CGSize PhysicalPixelSizeOfScreen(UIScreen *s) {
    CGSize result = s.bounds.size;

    if ([s respondsToSelector: @selector(scale)]) {
        CGFloat scale = s.scale;
        result = CGSizeMake(result.width * scale, result.height * scale);
    }

    return result;
}

iPhone 4 { 640.0, 960.0 }.

+5

img.png@2x? .

, , 320x480.

+1
source

Source: https://habr.com/ru/post/1787257/


All Articles