开发者

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

开发者 https://www.devze.com 2023-02-10 11:39 出处:网络
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 n

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

精彩评论

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