如何捕获UIView作为当前可见帧之外的图像?

时间:2015-07-13 11:14:28

标签: ios objective-c uiview

有没有办法将UIView捕获到当前不可见或者不在帧中的UIImage。在我现在使用的代码下面:

UIGraphicsBeginImageContextWithOptions(_myView.bounds.size, _myView.opaque, 0.0f);
[theView drawViewHierarchyInRect:_myView.bounds afterScreenUpdates:NO];
UIImage * snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

1 个答案:

答案 0 :(得分:1)

试试这个 -

-(UIImage *)imageFromView:(UIView *)myView{ 
     UIGraphicsBeginImageContextWithOptions(myView.bounds.size, myView.opaque, [UIScreen mainScreen].scale); 
     [myView.layer renderInContext:UIGraphicsGetCurrentContext()];
     UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
     UIGraphicsEndImageContext();
     return image;
  }