【读书笔记】iOS-截屏功能的实现。

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

一,整个工程文件。

二,代码

ViewController.m

#import "ViewController.h"

#import <QuartzCore/QuartzCore.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}

#PRagma -mark -doClickActions

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

[self screenShot];

}

#pragma -mark -functions

//截屏功能

-(void) screenShot

{

UIGraphicsBeginImageContext(self.view.bounds.size);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *image= UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

NSLog(@"image:%@",image);

UIImageView *imaView = [[UIImageView alloc] initWithImage:image];

imaView.frame = CGRectMake(0, 700, 500, 500);

[self.view addSubview:imaView];

UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航