title: Swift: Cropping a Screenshot without TabBar and NavigationBar
body: <p>I have a screenshot of the entire screen, <code>screenshot</code>, generated using the following: </p>
  
  <pre><code>let layer = UIApplication.sharedApplication().keyWindow!.layer
  let scale = UIScreen.mainScreen().scale
  UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale);
  
  layer.renderInContext(UIGraphicsGetCurrentContext())
  let screenshot = UIGraphicsGetImageFromCurrentImageContext()
  UIGraphicsEndImageContext()
  </code></pre>
  
  <p>I'd like to crop it so that the tab bar is not included, and I tried using the following code: </p>
  
  <pre><code>let crop = CGRectMake(0, 0, //"start" at the upper-left corner
  self.view.bounds.width, //include half the width of the whole screen
  self.view.bounds.height + self.navigationController!.navigationBar.frame.height) //include the height of the navigationBar and the height of view
  
  let cgImage = CGImageCreateWithImageInRect(screenshot.CGImage, crop)
  let image: UIImage = UIImage(CGImage: cgImage)!
  </code></pre>
  
  <p>This code results in <code>image</code> showing just a small portion of the screen, a rectangle starting at the upper-left corner of the screen (0, 0), and extending right for less than half the width of the screen, then downward for less than half the height of the screen. I'd like, though, for it to include the <em>entire</em> screen, except for the region occupied by the tab bar. Is there a such a way to crop it? </p>