Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Objective c 如何在mac app中获得屏幕分辨率的纵横比_Objective C_Macos_Aspect Ratio - Fatal编程技术网

Objective c 如何在mac app中获得屏幕分辨率的纵横比

Objective c 如何在mac app中获得屏幕分辨率的纵横比,objective-c,macos,aspect-ratio,Objective C,Macos,Aspect Ratio,我试图得到屏幕分辨率的纵横比,下面是我的代码,从中我可以得到宽度高度和刷新率 -(void)getSupportedDisplays{ NSArray* theref = (__bridge NSArray *)(CGDisplayCopyAllDisplayModes ( CGMainDisplayID(), nil )); NSMutableArray * rezes = [[NSMutableArray alloc]init]; for (id aMod

我试图得到屏幕分辨率的纵横比,下面是我的代码,从中我可以得到宽度高度和刷新率

-(void)getSupportedDisplays{

    NSArray* theref  =  (__bridge NSArray *)(CGDisplayCopyAllDisplayModes ( CGMainDisplayID(), nil ));

    NSMutableArray * rezes = [[NSMutableArray  alloc]init];

    for (id aMode  in theref) {
        CGDisplayModeRef  thisMode = (__bridge CGDisplayModeRef)(aMode);
        size_t theWidth = CGDisplayModeGetWidth( thisMode );
        size_t theHeight = CGDisplayModeGetHeight( thisMode );
        double refresh = CGDisplayModeGetRefreshRate(thisMode);
        NSString *theRez = [NSString stringWithFormat:@"%zux%zu %d Hz",theWidth,theHeight,(int)refresh];

        if (![rezes containsObject:theRez]) {
            [rezes addObject:theRez];
        }
    }

    NSLog(@" display deatails = %@", rezes);


}
我希望每个分辨率的纵横比都像这样

有什么建议吗


提前感谢

你可以从宽度和高度得到纵横比,你所需要的只是找到宽度和高度的最大公因数

static int gcd (int a, int b) {
    return (b == 0) ? a : gcd (b, a%b);
}
这将返回最大的共同因素

  int commanDivideFactor = gcd(theWidth, theHeight);

  NSLog(@"%d : %d", theWidth/commanDivideFactor, theHeight/commanDivideFactor);