@kingw
2016-04-20T23:43:43.000000Z
字数 589
阅读 1993
CALayer 截图 相册: ios
- (IBAction)btnClick:(UIButton *)sender {UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0);CGContextRef ctx = UIGraphicsGetCurrentContext();// 将要保存的view绘制到上下文中[self.view.layer renderInContext:ctx];UIImage *img = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();// 将图片保存到相册UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);}// 图片保存到相册掉用,固定写法- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{if (error) {NSLog(@"保存失败");}else{NSLog(@"保存成功");}}