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);
随机推荐
- 【python】python新手必碰到的问题---encode与decode,中文乱码[转]
转自:http://blog.csdn.net/a921800467b/article/details/8579510 为什么会报错“UnicodeEncodeError:'ascii' codec ...
- Unity3d 检查哪些prefab引用了某个UIAtlas
适用情景:策划在用NGUI制作UI prefab时经常会使用一些临时的Atlas,然后再想改就不知道都哪些使用了.现在想修改下使用临时资源的GameObject 使用方式,先选中某个prefab或者某 ...
- 提高AdoQuery的速度
用TDataSet及其派生类如TAdoQuery对数据库进行查找时, 如果TDataSet类 没有与数据感知控件相连,通过调用DisableControls可以极大地提高查询速度 特别是在数据比较多的 ...
- [转] Git 基础 - 打标签
2.6 Git 基础 - 打标签 打标签 同大多数 VCS 一样,Git 也可以对某一时间点上的版本打上标签.人们在发布某个软件版本(比如 v1.0 等等)的时候,经常这么做.本节我们一起来学习如何列 ...
- [转]Android How to Download and Make Volley.jar
原文来自:http://tips.androidhive.info/2015/08/android-how-to-download-and-make-volley-jar/ 1 Comment . ...
- Effective C++ -----条款40:明智而审慎地使用多重继承
多重继承比单一继承复杂.它可能导致新的歧义性,以及对virtual继承的需要. virtual继承会增加大小.速度.初始化(及赋值)复杂度等等成本.如果virtual base classes不带任何 ...
- 【linux】学习4
文件压缩: gzip :压缩 解压缩 zcat: 读取压缩文件 gzip text1 :压缩text1 得到 text1.gz 原文件不见了 gzip -c text1 > text1.g ...
- 【Git】笔记4 分支管理1
1.创建与合并分支 一开始的时候,master分支是一条线,Git用master指向最新的提交,再用HEAD指向master,就能确定当前分支,以及当前分支的提交点: 每次提交,master分支都会向 ...
- HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛
题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...
- 使用WKWebView替换UIWebView
开发App的过程中,常常会遇到在App内部加载网页,通常用UIWebView加载.这个自iOS2开始使用的网页加载器一直是开发的心病:加载速度慢,占用内存多,优化困难.如果加载网页多,还可能因为过量占 ...