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

前端 未结 4 1662
佛祖请我去吃肉
佛祖请我去吃肉 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:20

    This code worked for me

    - (UIImage *)captureScreenInRect:(CGRect)captureFrame {
        CALayer *layer;
        layer = self.view.layer;
        UIGraphicsBeginImageContext(self.view.bounds.size); 
        CGContextClipToRect (UIGraphicsGetCurrentContext(),captureFrame);
        [layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return screenImage;
    }
    

提交回复
热议问题