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
ios摇一摇截屏代码的更多相关文章
- ios截屏代码[转]
http://www.cnblogs.com/chenxiangxi/p/3547974.html 这位博主的连接中将ios自定义大小位置的截屏代码写的很不错,马上就能用的方法,对于只想马上用的程序员 ...
- iOS截屏代码
转载自:http://m.open-open.com/m/code/view/1420469506375 1.普通界面 /** *截图功能 */ -(void)screenShot{ UIGraphi ...
- iOS中正确的截屏姿势
昨天写了个用到截屏功能的插件,结果问题不断,今天终于解决好了,把debug过程中所有尝试过的截屏方法都贴出来吧- 第一种 这是iOS 3时代开始就被使用的方法,它被废止于iOS 7.iOS的私有方法, ...
- iOS - Quartz 2D 手势截屏绘制
1.绘制手势截屏 具体实现代码见 GitHub 源码 QExtension QTouchClipView.h @interface QTouchClipView : UIView /** * 创建手势 ...
- 【转】Android 音量键+电源键 截屏代码小结
http://104zz.iteye.com/blog/1752961 原文地址:http://blog.csdn.net/hk_256/article/details/7306590 ,转载请注明出 ...
- iOS 点击按钮截屏
@interface CaptureViewController () @property (nonatomic, strong) UIImageView *backgrounView; //控制器背 ...
- VC++ 截屏代码,并保存为想要的格式(BMP,JPG,PNG,GIF等格式)
void CCaptionScreenDlg::Screen(char* filename) { HDC hdcSrc = ::GetDC(NULL); int nBitPerPixel = GetD ...
- unity中编辑器直接截屏代码
using UnityEngine; using System.Collections; using System.Windows.Forms; public class screenshots : ...
- Activity禁止截屏代码
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
随机推荐
- PDF.js
http://www.linuxidc.com/Linux/2015-06/118728.htm http://blog.csdn.net/xiangcns/article/details/42089 ...
- Unity3d《Shader篇》Logo闪光特效
Shader "Custom/Flash" { Properties { _MainTex ("Base (RGB)", 2D) = "white&q ...
- git命令使用
2015-07-15 11:59:11 git pull : 相当于 SVN up git status : 相当于 SVN st git add a.txt: 新添加文件 或者 将文件修改保存到索引 ...
- java web 学习 --第一天(Java三级考试)
1.Servlet servlet是运行在web server或 application server端的Java程序,主要用于在服务器端产生动态内容. servlet 在服务器端主要有以下作用 读取 ...
- checksum table 【转】
来自:http://dinglin.iteye.com/blog/1791922 有同学问到 checksum table在逻辑备份时候前后是否可以用于验证数据一致性.扩展一下发现有一些有趣的问题,比 ...
- 将jquery和公共样式缓存到localStorage,可以减少Http请求,从而优化页面加载时间
以下代码: //入口函数 if (window.localStorage) { initJs(); initCss("css", "/gfdzp201508257998/ ...
- HTML5基本标签、样式
感觉在Sublime Text3中写起来比较方便~~ 将HTML5中要用到的基本标签全部放在了一起,没有好好的整理,为了自己记忆的方便,就先这样写下来了~~ <!DOCTYPE html> ...
- 【leetcode】Pascal's Triangle I & II (middle)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【python】入门学习(五)
字符串: 正索引,从0开始 和 负索引,从-1开始 >>> s = 'apple' >>> s[0] 'a' >>> s[1] 'p' >& ...
- 20145213《Java程序设计学习笔记》第六周学习总结
20145213<Java程序设计学习笔记>第六周学习总结 说在前面的话 上篇博客中娄老师指出我因为数据结构基础薄弱,才导致对第九章内容浅尝遏止地认知.在这里我还要自我批评一下,其实我事后 ...