我想显示所有兼容的屏幕分辨率,但只获得很少的分辨率,即通过nil
时获得的分辨率
达到CGDisplayCopyAllDisplayModes
相同的分辨率,即使我将kCGDisplayShowDuplicateLowResolutionModes
传递给kCFBooleanTrue
我正在使用的以下块。
+(NSArray *)menuItemsForCurrentDisplay :(CGDirectDisplayID)display{
//Get Current mode
CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(display);
// Use a dictionary with title keys to avoid 'duplicates'
NSMutableDictionary *menuItemsByTitle = [NSMutableDictionary new];
// Get Number of Supported Displays
// NSArray* numberOfDisplayModes = (__bridge NSArray *)(CGDisplayCopyAllDisplayModes ( display, nil ));
CFStringRef keys[1] = { kCGDisplayShowDuplicateLowResolutionModes };
CFBooleanRef values[1] = { kCFBooleanTrue };
CFDictionaryRef options = CFDictionaryCreate(kCFAllocatorDefault, (const void**) keys, (const void**) values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
NSArray* numberOfDisplayModes = (__bridge NSArray *)CGDisplayCopyAllDisplayModes(display, options);
for (int i = 0; i < numberOfDisplayModes.count; i++) {
if (CGDisplayModeIsUsableForDesktopGUI((__bridge CGDisplayModeRef)(numberOfDisplayModes[i]))) {
DisplayModeMenuItem *menuItem = [[DisplayModeMenuItem alloc] initWithCustomDisplay:display andMode:(__bridge CGDisplayModeRef)(numberOfDisplayModes[i])];
DisplayModeMenuItem *previousMenuItem = menuItemsByTitle[menuItem.title];
if (previousMenuItem == nil) {
if (currentMode == (__bridge CGDisplayModeRef)(numberOfDisplayModes[i])|| previousMenuItem.state == NSOnState) {
[menuItem setState:NSOnState];
}
menuItemsByTitle[menuItem.title] = menuItem;
}else if ((__bridge CGDisplayModeRef)(numberOfDisplayModes[i]) == currentMode ){
[menuItem setState:NSOnState];
}
}
}
CFRelease(options);
CGDisplayModeRelease(currentMode);
NSLog(@"menuItemsByTitle %@",[menuItemsByTitle allValues]);
return [[menuItemsByTitle allValues] sortedArrayUsingSelector:@selector(customCompare:)];
}