How to capture current view screenshot and reuse in code? (iPhone SDK)

前端 未结 4 1727
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 07:56

I am attemting to transition from one UIView to another, when the user rotates the device. This, in of itself, is not difficult. However, since I am displaying completely di

4条回答
  •  误落风尘
    2020-11-28 08:18

    - (UIImage *)captureView:(UIView *)view {
        CGRect screenRect = [[UIScreen mainScreen] bounds];
    
        UIGraphicsBeginImageContext(screenRect.size);
    
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        [[UIColor blackColor] set];
        CGContextFillRect(ctx, screenRect);
    
        [view.layer renderInContext:ctx];
    
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
        UIGraphicsEndImageContext();
    
        return newImage;
    }
    

    Found this here :

    http://discussions.apple.com/thread.jspa?messageID=8358740

提交回复
热议问题