Search code examples
iosglkview

how to set contentScaleFactor iOS


Following is not working.

    GLKView *view = (GLKView *)self.view;
    view.contentScaleFactor=1.0;

logging the view and [UIScreen mainScreen] objects:

<GLKView: 0x15638f60; frame = (0 0; 320 568); autoresize = RM+BM; layer = <CAEAGLLayer: 0x15638960>>
<UIScreen: 0x15629a60; bounds = {{0, 0}, {320, 568}}; mode = <UIScreenMode: 0x15629c40; size = 640.000000 x 1136.000000>>

and [[UIScreen mainScreen] scale]; is still 2.0 not 1.0

Do i need to set scale factor on some other object?


Solution

  • [UIScreen mainScreen].scale is the actual scale of the physical device the user is using.

    (It is always "2.0" unless you have incredibly old machines. "3.0" machines are coming soon from Apple, 2014 apparently.)

    Here's a typical example...

        float isf = 1.0 / [UIScreen mainScreen].scale;
    
        CGPatternRef strokePattern = CGPatternCreate(
                        NULL,
                        CGRectMake(0,0,wholeWidth,wholeHeight),
    
                        CGAffineTransformScale(
                            CGAffineTransformIdentity,
                            isf,-isf),
    
                        wholeWidth,wholeHeight,
                        kCGPatternTilingNoDistortion,
                        true,
                        &kPatternCallbacks);
    

    hope it helps in some way!