码迷,mamicode.com
首页 > 移动开发 > 详细

iOS-截屏功能的实现。

时间:2015-08-12 21:17:08      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

一,整个工程文件。

 

技术分享

 

二,代码

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);
    
}
技术分享

 

 

 
 

iOS-截屏功能的实现。

标签:

原文地址:http://www.cnblogs.com/yang-guang-girl/p/4725259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!