title: UIView Greyscale , animation and performance issues
body: <p>I'm developing an app and i'm implementing an application to manage orders some orders of a client.
  In this view i have implemented a facebook style menu ( the new one that appears by shifting the whole window right) and i'have added a greyscale effect to the main view when it's shifted to right.
  I've accomplished it by creating a UIImage of the current screen and by adding it over the real view and animating it's alpha from 1 to 0
  Here's the code i've used to</p>
  
  <pre><code>-(void)toggleMenu {
      UIGraphicsBeginImageContext(self.view.bounds.size);
      [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
      if (![menu isOpened]){
          UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
          UIGraphicsEndImageContext();
          UIImage *blackAndWhiteImage = [UIImage getBlackAndWhiteVersionOfImage:viewImage];
          overlayImage = [[UIImageView alloc]initWithImage:blackAndWhiteImage];
          overlayImage.alpha = 0.1;
          overlayImage.userInteractionEnabled=NO;
          [self.view addSubview:overlayImage];
      }
  
      [UIView animateWithDuration:0.3 animations:^{
          CGRect newRect = [self tabBarController].view.frame;
          if (![menu isOpened]){
              newRect.origin.x += 150;
              [menu setOpened:YES];
              overlayImage.alpha = 1.0;
          } else {
              newRect.origin.x -= 150;
              [menu setOpened:NO];
              overlayImage.alpha = 0;
          }
          [self tabBarController].view.frame = newRect;
  
      } completion:^(BOOL finished){
          if(![menu isOpened]){
              [overlayImage removeFromSuperview];
              overlayImage = nil;
          }
      }];
  }
  </code></pre>
  
  <p>The problem is that i'm having issues with performances during animation ( little with iPhone 4 i'm trying an 3gs in next hours... ) </p>
  
  <p>Does anyone have any suggestions on what to do to get better performances ? 
  Regards </p>
  
  <pre><code>+ (UIImage *)getBlackAndWhiteVersionOfImage:(UIImage *)anImage {
  UIImage *newImage;
  
  if (anImage) {
      CGColorSpaceRef colorSapce = CGColorSpaceCreateDeviceGray();
      CGContextRef context = CGBitmapContextCreate(nil, anImage.size.width * anImage.scale, anImage.size.height * anImage.scale, 8, anImage.size.width * anImage.scale, colorSapce, kCGImageAlphaNone);
      CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
      CGContextSetShouldAntialias(context, NO);
      CGContextDrawImage(context, CGRectMake(0, 0, anImage.size.width, anImage.size.height), [anImage CGImage]);
  
      CGImageRef bwImage = CGBitmapContextCreateImage(context);
      CGContextRelease(context);
      CGColorSpaceRelease(colorSapce);
  
      UIImage *resultImage = [UIImage imageWithCGImage:bwImage];
      CGImageRelease(bwImage);
  
      UIGraphicsBeginImageContextWithOptions(anImage.size, NO, anImage.scale);
      [resultImage drawInRect:CGRectMake(0.0, 0.0, anImage.size.width, anImage.size.height)];
      newImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
  }
  
  return newImage;
  </code></pre>
  
  <p>}</p>