Jonathan
Jonathan

Reputation: 913

Hide an element in a view just before to take a screen shot

I try to hide an element in a view just before to take a screen shot.

-(void)method{
  [self.element setHidden:YES];
  UIImage *image = [self screenShot];
}


- (UIImage *)screenShot {
  UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, 0);
  [self.view drawViewHierarchyInRect:self.view.frame afterScreenUpdates:NO];
  UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  return newImage;
}

But the element is on the screen shot image. How to force refreshing the view to hide the element in the screen shot ? Thanks by advance.

Upvotes: 0

Views: 844

Answers (1)

Paul.s
Paul.s

Reputation: 38728

When using drawViewHierarchyInRect:afterScreenUpdates: ensure that you take the snapshot after your updates have been applied by passing YES as the second argument

Upvotes: 2

Related Questions