iOS 毛玻璃效果

发布于 2016-07-22 / iOS / 0条评论 / 2,641浏览

设置手势密码后,按下home键,防止别人拿到手机“多任务”模式下看到里面的内容,所以在按下home键生成一个毛玻璃的图片盖在上面。

UIImage *screenImage = [UIImage grabScreenWithScale:1];// 截屏
UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, mScreenWidth, mScreenHeight)];
imageView.image = screenImage;
[self.window addSubview:imageView];

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, screenImage.size.width, screenImage.size.height)];
toolbar.barStyle = UIBarStyleBlackOpaque;
[imageView addSubview:toolbar];
+ (UIImage *)grabScreenWithScale:(CGFloat)scale
{
    UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
    //    UIGraphicsBeginImageContext(screenWindow.frame.size);
    UIGraphicsBeginImageContextWithOptions(screenWindow.frame.size, YES, scale);
    [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

效果参考:http://www.jianshu.com/p/6dd0eab888a6

评论
站长统计