ui_orientation,一种来自Apple的无证珍珠

Spa*_*Dog 4 iphone ipad ios

我在WWDC视频上看到了这个ui_orientation糖果,用于此背景

UIImage *finalImage = [[UIImage alloc] initWithCGImage:cgimg
                      scale:2.0f orientation:ui_orientation([displayImage properties])];
Run Code Online (Sandbox Code Playgroud)

显然它会正确地读取CCImage的方向来创建UIImage,但在我的代码中使用它会产生这个错误:函数'ui_orientation'的隐式声明在C99中无效

你们知道我应该在源代码中包含什么标题来使这个功能起作用吗?

谢谢.

注意:WWDC 2012 - 第25课,25'16"......创建UIImage时

nev*_*ing 6

这是来自会话422,他们在那里提供代码

将orientation属性转换为UIImageOrientation:

UIImageOrientation ui_orientation (NSDictionary* props)
{
    int o = [[props valueForKey:(id)kCGImagePropertyOrientation] intValue];
    UIImageOrientation map[] = {
        UIImageOrientationUp,
        UIImageOrientationUp, UIImageOrientationUpMirrored,
        UIImageOrientationDown, UIImageOrientationDownMirrored,
        UIImageOrientationLeftMirrored, UIImageOrientationRight,
        UIImageOrientationRightMirrored, UIImageOrientationLeft,
    };
    return map[o];
}
Run Code Online (Sandbox Code Playgroud)

这里也是一个方便的提示:从所有WWDC会话中下载所有PDF并将它们保存在硬盘上.他们不占用太多空间.这样,当您想要查找会话CATransaction或(如此处)组成的功能时,您可以使用Spotlight查找PDF,其中会话编号作为其标题.