title: When I take screenshot of UIView, why do I get a transparent strip on and how to determine the strip height programatically?
body: <p>I make a simple program to take screenshot</p>
  
  <p>The purpose is for a trick of displaying a not so full screen modal. Take screenshot of the presentingViewController and then display that on background.</p>
  
  <pre><code>#import &lt;QuartzCore/CALayer.h&gt;
  
  @implementation UIView (screenshot)
  - (UIImage*) screenshot
  {
      UIGraphicsBeginImageContext(self.bounds.size);
      [self.layer renderInContext:UIGraphicsGetCurrentContext()];
      UIImage *myImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();
      return myImage;
  }
  
  @end
  </code></pre>
  
  <p>Simple enough. </p>
  
  <p>Now I do:
  [BGMDCachedProperties singleton].screenShotOfLastPresentingController = self.navigationController.view.screenshot;//Take the screen shot, put it in a variable</p>
  
  <p>Then I do
      [[BGMDCachedProperties singleton].screenShotOfLastPresentingController saveScreenshot];</p>
  
  <pre><code>-(void)saveScreenshot{
      NSData * data = UIImagePNGRepresentation(self);
      NSString * documentDirectory= [BGMDApplicationsPointers applicationDocumentsDirectory];
      NSString * fileForDocumentDirectory = [documentDirectory stringByAppendingFormat:@"/%@",@"foo.png"];
      BOOL result = [data writeToFile:fileForDocumentDirectory atomically:YES];
      if (result)
      {
  
      }
  }
  </code></pre>
  
  <p>This is what I got:
  <img src="https://i.stack.imgur.com/bDdH4.png" alt="enter image description here"></p>
  
  <p>Then I display a mock viewController whose purpose is to display that image. Maybe I just misinterpret that foo.png right? I set the background to red so we know</p>
  
  <p>This is what I got:
  <img src="https://i.stack.imgur.com/gEc1F.png" alt="enter image description here"></p>
  
  <p>Obviously that doesn't work for my purpose because I will need to do this:</p>
  
  <p><img src="https://i.stack.imgur.com/UZqFy.png" alt="enter image description here"></p>
  
  <p>Finally I managed to get it fixed by just getting rid the top 20 points of the screenshot. </p>
  
  <pre><code>theScreenshot = theScreenshot.crop20PointsifStatusBarShowsUp;
  
  -(UIImage*) crop20PointsifStatusBarShowsUp
  {
      if ([BGMDApplicationsPointers statusBarShowUp])
      {
          CGRect newSize = CGRectMake(0, sizeOfStatusBar, self.size.width, self.size.height-sizeOfStatusBar);
          UIImage * newImage = [self cropUIImageWithCGRect:newSize];
          return newImage;
      }
      else{
          return [self copy];
      }
  }
  </code></pre>
  
  <p>I finally got it work:
  <img src="https://i.stack.imgur.com/6P5EC.png" alt="enter image description here">
  However, if a user allow personal hotspot, their status bar would be 40 points instead.</p>
  
  <p>I wonder why the transparent strip shows up at navigationController.view given that like all view, navigation controller is only supposed to fill the screen that's "available" rather than the whole screen.</p>
  
  <p>Also how do I know the size of the strip? Sometimes it's 0 when there is not status bar, sometimes it's 20, and sometimes it's 40.</p>
  
  <p>I added these 2 codes:</p>
  
  <pre><code>PO(NSStringFromCGRect(self.frame));
  PO(NSStringFromCGSize(myImage.size));
  </code></pre>
  
  <p>and got:</p>
  
  <pre><code>2012-10-12 07:57:34.627 BadgerNew[3354:907] &lt;0x1cdc8a60 UIView+screenshot.m:(21)&gt; NSStringFromCGRect(self.frame): {{0, 0}, {320, 431}}
  2012-10-12 07:57:34.629 BadgerNew[3354:907] &lt;0x1cdc8a60 UIView+screenshot.m:(22)&gt; NSStringFromCGSize(myImage.size): {320, 431}
  </code></pre>