Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ui_orientation, one more undocumented pearl from Apple

Tags:

ios

iphone

ipad

I saw this ui_orientation candy on a WWDC video, used on this context

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

apparently it reads the orientation of the CCImage to create the UIImage properly, but using this on my code produces this error: implicit declaration of function 'ui_orientation' is invalid in C99

Do you guys know what header should I include on my source to make this function work?

thanks.

NOTE: WWDC 2012 - lesson 510 at 25'16" ... when the UIImage is created

like image 206
Duck Avatar asked Jan 13 '23 16:01

Duck


1 Answers

This is from Session 422, where they give the code

Convert the orientation property to 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];
}

Here's a handy tip too: Download all the PDFs from all the WWDC sessions and keep them on your hard drive. They don't take up much space. That way when you want to find what session talks about CATransaction or (like here) a made up function, you can use Spotlight to find the PDF, which has the session number as its title.

like image 66
nevan king Avatar answered Jan 19 '23 12:01

nevan king