当前位置: 代码迷 >> Iphone >> iphone app开发心得(三)
  详细解决方案

iphone app开发心得(三)

热度:80   发布时间:2016-04-25 06:28:06.0
iphone app开发经验(三)
1.xcode之宏



2.怎样从ipa中提取PNG文件



3.CALayer简单教程



4.两个有用的颜色

[UIColor colorWithRed:0.75 green:0.75 blue:0.75 alpha:1.0], // Silver
[UIColor colorWithRed:1.00 green:0.84 blue:0.00 alpha:1.0], // Gold

5.在 cocos2d 中将屏幕内容截取为图片
+ (UIImage*) screenshotUIImage{    CGSize displaySize  = [[CCDirector sharedDirector] displaySizeInPixels];    CGSize winSize      = [[CCDirector sharedDirector] winSizeInPixels];    //Create buffer for pixels    GLuint bufferLength = displaySize.width * displaySize.height * 4;    GLubyte* buffer = (GLubyte*)malloc(bufferLength);    //Read Pixels from OpenGL    glReadPixels(0, 0, displaySize.width, displaySize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);    //Make data provider with data.    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, bufferLength, NULL);    //Configure image    int bitsPerComponent = 8;    int bitsPerPixel = 32;    int bytesPerRow = 4 * displaySize.width;    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;    CGImageRef iref = CGImageCreate(displaySize.width, displaySize.height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);    uint32_t* pixels = (uint32_t*)malloc(bufferLength);    CGContextRef context = CGBitmapContextCreate(pixels, winSize.width, winSize.height, 8, winSize.width * 4, CGImageGetColorSpace(iref), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);    CGContextTranslateCTM(context, 0, displaySize.height);    CGContextScaleCTM(context, 1.0f, -1.0f);    switch ([CCDirector sharedDirector].deviceOrientation)    {        case CCDeviceOrientationPortrait: break;        case CCDeviceOrientationPortraitUpsideDown:            CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(180));            CGContextTranslateCTM(context, -displaySize.width, -displaySize.height);            break;        case CCDeviceOrientationLandscapeLeft:            CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(-90));            CGContextTranslateCTM(context, -displaySize.height, 0);            break;        case CCDeviceOrientationLandscapeRight:            CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(90));            CGContextTranslateCTM(context, displaySize.height-displaySize.width, -displaySize.height);            break;    }    CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, displaySize.width, displaySize.height), iref);    CGImageRef imageRef = CGBitmapContextCreateImage(context);    UIImage *outputImage = [[[UIImage alloc] initWithCGImage:imageRef] autorelease];    //Dealloc    CGImageRelease(imageRef);    CGDataProviderRelease(provider);    CGImageRelease(iref);    CGColorSpaceRelease(colorSpaceRef);    CGContextRelease(context);    free(buffer);    free(pixels);    return outputImage;}


6.禁止锁屏
[UIApplication sharedApplication].idleTimerDisabled=YES;

  相关解决方案