最近看其他大神的代碼,自己也需要不斷的總結(jié)。下面總結(jié)了幾種屏幕截圖的方法
1種是最簡(jiǎn)單的方法
UIView*snapshot;
?snapshot =[inputViewsnapshotViewAfterScreenUpdates:YES];
?inputView//是要截屏的那個(gè)view牛郑。上面參數(shù)YES或者NO代表渲染之后,或者之前。
2種方法是截取屏幕然后轉(zhuǎn)化成UIImage
UIGraphicsBeginImageContextWithOptions(inputView.bounds.size,NO,0);//這個(gè)也可以用下面注釋了得一行代碼平委,一樣的效果.
//UIGraphicsBeginImageContext(inputView.bounds.size);
UIGraphicsBeginImageContext(inputView.bounds.size);
[inputView.layerrenderInContext:UIGraphicsGetCurrentContext()];//把當(dāng)前view的內(nèi)容增加到當(dāng)前截取的圖片中
UIImage*image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Create an image view.
UIView*snapshot = [[UIImageView ?alloc]initWithImage:image];