CFDictionaryCreate [NSDictionary dictionaryWithObject ...]的模拟

时间:2012-06-10 14:33:34

标签: iphone objective-c ipad core-foundation

我正在寻找创建以下字典的方法

    NSDictionary *frameProperties = [NSDictionary dictionaryWithObject:[NSDictionary 
                                                  dictionaryWithObject:[NSNumber numberWithInt:2] 
                                                                forKey:(NSString *) kCGImagePropertyGIFDelayTime]
                                     forKey:(NSString *) kCGImagePropertyGIFDictionary];

通过CoreFoundation,即CFDictionaryCreate

任何想法如何实现这个?

1 个答案:

答案 0 :(得分:3)

似乎我自己构建了答案,请确认某人。代码编译正常,但我还无法测试它。

    int delayOnEachFrame = 2;
    const void *tkeys[1] = { kCGImagePropertyGIFDelayTime };
    const void *tvalues[1] = { CFNumberCreate(0, kCFNumberSInt32Type, &delayOnEachFrame) };
    CFDictionaryRef tframeProperties = CFDictionaryCreate(NULL, tkeys, tvalues, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

    const void *keys[1] = { kCGImagePropertyGIFDictionary };
    const void *values[1] = { tframeProperties };
    CFDictionaryRef frameProperties = CFDictionaryCreate(NULL, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);