• ios摇一摇截屏代码


    #import "ViewController.h"

     

    @interface ViewController ()

     

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        //1.添加一个视图

        UIView *greenView=[[UIView alloc]init];

        greenView.frame=CGRectMake(100, 100, 100, 100);

        greenView.backgroundColor=[UIColor greenColor];

        [self.view addSubview:greenView];

        //设置第一响应事件(必须做的)

        [self becomeFirstResponder];

        

        

    }

    -(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event

    {

        if (motion==UIEventSubtypeMotionShake) {

            //截屏

            [self snapshot];

        }

    }

     

    //截屏

    -(void)snapshot

    {

        //开启上下文

        UIGraphicsBeginImageContext(self.view.bounds.size);

        //拿到上下文

        CGContextRef context=UIGraphicsGetCurrentContext();

        [self.view.layer renderInContext:context];

        UIImage *image=UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        //保存到相册

        UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

    }

    - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo

    {

        if (!error) {

            NSLog(@"save success");

        }

        

    }

     

    @end

  • 相关阅读:
    Qt5.3.2(VS2010)_调试_进入Qt源码
    Qt5.3.2(VS2010)_调试_遇到的问题
    Qt_QString::split测试
    Qt_QString.indesOf和mid测试
    激活_目标窗口
    DrawDibDraw__ZC测试
    【转】DrawDibDraw
    数学运算_基本_01
    get和post请求及进程和线程及cookie和session的区别
    Redis性能优化之redis.cnf配置文件
  • 原文地址:https://www.cnblogs.com/tangranyang/p/4660233.html
Copyright © 2020-2023  润新知