你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS-截屏功能的實現。

iOS-截屏功能的實現。

編輯:IOS開發綜合

一,整個工程文件。

 

\

 

二,代碼

ViewController.m

 
#import ViewController.h
#import 

@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);
    
}
 

 

 
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved