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);
随机推荐
- POJ 3728
http://poj.org/problem?id=3278 题目大意就是在同一坐标轴上给你一个人的坐标,一个牛的坐标,而人的运动每一次运动有三种方式,一种是后退1,一种是前进1,还有一种是坐标翻倍, ...
- WebViewer报错Error loading document: Invalid XOD file: Zip end header data is wrong size!
错误:Error loading document: Invalid XOD file: Zip end header data is wrong size! 解决:https://groups.go ...
- Codeforces 55D
基本的数位DP,注意记录那些状态可以用最小的空间判断出整除性. #include <cstdio> #include <cstring> using namespace std ...
- 错误日志中关于innodb的问题收集
1.错误日志报告如下: ..... 120223 23:36:06 InnoDB: Compressed tables use zlib 1.2.3 120223 23:36:06 InnoDB: I ...
- 安装VisualSvn Server时遇到的问题
安装标准版VisualSvnserver,端口443,启用https//,安装过程中报服务启动失败,后用命令行 msiexec /i VisualSVN-Server-2.7.3.msi NO_STA ...
- C# 串口操作系列(2) -- 入门篇,为什么我的串口程序在关闭串口时候会死锁 ?
第一篇文章我相信很多人不看都能做的出来,但是,用过微软SerialPort类的人,都遇到过这个尴尬,关闭串口的时候会让软件死锁.天哪,我可不是武断,算了.不要太绝对了.99.9%的人吧,都遇到过这个问 ...
- MyEclipse在线安装maven插件最新地址
http://repository.sonatype.org/content/sites/forge-sites/m2e/0.10.0/S/20100209-0800/
- ajax+bootstrap做弹窗
建页面,引入bootstrap弹窗 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...
- 让UserControl能显示焦点状态
'set the control can display the focus status Protected Overrides Sub OnGotFocus(ByVal e As System.E ...
- September 25th 2016 Week 40th Sunday
Everything is good in its season. 万物逢时皆美好. Don't lose hope. Remeber that even a dog has its day. Onc ...