title: iOS 6 - My application lags when gesture is recognized and UIActivityIndicator doesn't show. What do i need to do?
body: <p>I have added a gesture recognizer (two finger tap) that detects when the user presses on an image in UIWebView and brings up a UIActivityViewController to save the image and other stuff. My problem is that when I press on an image there is a lag (depending on how big the image size may be) and what im trying to achieve is that when the user double taps on the image i want to show an activity indicator until the image is ready to be saved and etc... I may add that i think the problem is here 'imageToBeSaved = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];' after i take out that code, there is no more lagging. Here's my code:</p>
  
  <pre><code>// adding gesture recognizer to "website" (which is a "UIWebView")
  UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
  doubleTap.numberOfTouchesRequired = 2;
  [website addGestureRecognizer:doubleTap];
  
  // actions on gesture detect and call actionsOnImage for options
  -(void) doubleTap :(UITapGestureRecognizer*) sender {
  [loadingImageActivityIndicator startAnimating];
  int scrollPositionY = [[self.website stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
  int scrollPositionX = [[self.website stringByEvaluatingJavaScriptFromString:@"window.pageXOffset"] intValue];
  
  int displayWidth = [[self.website stringByEvaluatingJavaScriptFromString:@"window.outerWidth"] intValue];
  CGFloat scale = website.frame.size.width / displayWidth;
  
  CGPoint pt = [sender locationInView:self.website];
  pt.x *= scale;
  pt.y *= scale;
  pt.x += scrollPositionX;
  pt.y += scrollPositionY;
  
  NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).tagName", pt.x, pt.y];
  NSString *tagName = [self.website stringByEvaluatingJavaScriptFromString:js];
  
  if ([tagName compare:@"IMG" options:NSCaseInsensitiveSearch]==NSOrderedSame) {
      NSLog(@"tagName was IMG");
      NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", pt.x, pt.y];
      NSString *urlToSave = [self.website stringByEvaluatingJavaScriptFromString:imgURL];
      NSURL *url = [NSURL URLWithString:urlToSave];
      imageToBeSaved = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
      [website addSubview:loadingImageActivityIndicator];
  
      [self actionsOnImage];  // self made function with sharing capabilities (see below)
  }
  
  }
  
  - (void) actionsOnImage {
  [loadingImageActivityIndicator stopAnimating];
  
  NSArray* dataToShare = [[NSArray alloc] initWithObjects:imageToBeSaved, nil];
  UIActivityViewController* activityViewController =
  [[UIActivityViewController alloc] initWithActivityItems:dataToShare
                                    applicationActivities:nil];
  [self presentViewController:activityViewController animated:YES completion:^{}];
  }
  </code></pre>