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