截屏demo
实现思想。
将当前self.view renderIn 当前ImageContext
然后绘制。
demo结合 基于soclia发送微博
截屏DEMO2 //方法2
UIGetScreenImage方法 是apple的私有方法 有概率不让上架
UIImage *snapshot; CGImageRef cgScreen = UIGetScreenImage(); if (cgScreen) { snapshot = [UIImage imageWithCGImage:cgScreen]; CGImageRelease(cgScreen); } UIScreen *mainScreen = [UIScreen mainScreen]; CGSize size = [mainScreen bounds].size; CGFloat scale = [mainScreen scale]; CGFloat screenWidth = size.width * scale; CGFloat screenHeight = size.height * scale; CGRect rect=CGRectMake(0, 0, screenWidth, screenHeight); self.image = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([snapshot CGImage], rect)]; //res就是截图后的UII
需要导入
#import <QuartzCore/QuartzCore.h>
QuartzCore.framework
// // ViewController.m // LrnShareSNSDemo // // Created by liu poolo on 12-10-22. // Copyright (c) 2012年 liu poolo. All rights reserved. // #import "ViewController.h" #import <Social/Social.h> #import <QuartzCore/QuartzCore.h> @interface ViewController () @property UIImage *shareImage; @property NSString *shareText; @end @implementation ViewController @synthesize shareImage=_shareImage; - (void)viewDidLoad { [super viewDidLoad]; self.shareImage=[UIImage imageNamed:@"share_image.png"]; self.shareText=@"现在较为蛋疼的是 用ios6自带的social.framework 发出来的 在微博来源会显示是ios而不是iphoneX 而且如果默认输入字数如果超过了限制 他会不显示 略坑爹的说"; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)buttonPressed:(id)sender { NSArray *activityItem=nil; if (self.shareImage) { activityItem=@[self.shareImage,self.shareText]; //这里顺序无关,但是只能一个是image ,一个是nssting //如果是2个NNString的话就会导致 啥都不显示。 }else{ activityItem=@[self.shareText]; } UIActivityViewController *aVC=[[UIActivityViewController alloc]initWithActivityItems:activityItem applicationActivities:nil]; [self presentViewController:aVC animated:YES completion:nil]; } - (IBAction)screenShotPressed:(id)sender { UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self.shareImage=image; } @end