• iOS截屏保存至相册


    #pragma mark 截屏并保存至相册

    -(void)screenShotsComplete:(void(^)(UIImage * img)) complete

    {

        CGSize imageSize = [[UIScreen mainScreen] bounds].size;

        UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);

        

        CGContextRef context = UIGraphicsGetCurrentContext();

        

        for (UIWindow * window in [[UIApplication sharedApplication] windows]) {

            if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) {

                CGContextSaveGState(context);

                CGContextTranslateCTM(context, [window center].x, [window center].y);

                CGContextConcatCTM(context, [window transform]);

                CGContextTranslateCTM(context, -[window bounds].size.width*[[window layer] anchorPoint].x, -[window bounds].size.height*[[window layer] anchorPoint].y);

                [[window layer] renderInContext:context];

                

                CGContextRestoreGState(context);

            }

        }

        

        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);

        NSLog(@"Suceeded!");

        if(complete){

            complete(image);

        }

     

    }

     

    //点击保存至相册后,出现动画效果

    [self screenShotsComplete:^(UIImage *img) {

                UIImageView * imgView=[[UIImageView alloc]initWithFrame:weakSelf.view.bounds];

                imgView.image=img;

                [weakSelf.view addSubview:imgView];

                

                CGPoint center=CGPointMake(weakSelf.view.center.x, weakSelf.view.center.y-64);

                [UIImageView animateWithDuration:1.0f animations:^{

                    imgView.width-=imgView.width;

                    imgView.height-=imgView.height;

                    imgView.alpha=0.0f;

                    imgView.center=center;

                } completion:^(BOOL finished) {

                    [imgView removeFromSuperview];

                    btn.enabled=YES;

                    [HintInfoView showOnView:weakSelf.view hintTitle:@"保存成功!" hintFont:weakSelf.commonTitleFont];

                }];

                

                

            }];

        };

     

     

     

     

     

  • 相关阅读:
    linux学习笔记----权限与命令之间的关系(极重要)
    linux学习笔记----文件与目录管理
    Linux文件权限与目录配置
    linux:基本命令
    Java:正则表达式
    SDIBT 3237 Boring Counting( 划分树+二分枚举 )
    山东省第四届ACM大学生程序设计竞赛解题报告(部分)
    poj 3522 Slim Span (最小生成树kruskal)
    poj 1236 Network of Schools(又是强连通分量+缩点)
    poj 2762 Going from u to v or from v to u?(强连通分量+缩点重构图+拓扑排序)
  • 原文地址:https://www.cnblogs.com/daxueshan/p/5804060.html
Copyright © 2020-2023  润新知