开发者

What is the way to take a screenshot in app on iOS?

On iPhone, is there a way to tap a rounded rect button and take a screenshot, I don't want my users taking a photo by pressing sleep+home button! 开发者_如何学PythonWhat are the code and frameworks needed?


Here's a Class method that will return a UIImage of the UIView and CGRect you pass to it:

+ (UIImage *)captureView:(UIView *)view withArea:(CGRect)screenRect {

    UIGraphicsBeginImageContext(screenRect.size);

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [[UIColor blackColor] set];
    CGContextFillRect(ctx, screenRect);

    [view.layer renderInContext:ctx];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newImage;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜