title: Set alpha value for only a part of an UIImageView
body: <p>I have put 2 UIImageViews on top of each other. The bottom one is just a  green image and the top one is blue. On top of that I have a UIView. The idea is to be able to drag the UIView up and down, and instead of only seeing the green colour, the UIView will show the bottom image, the blue colour, inside its rectangle.</p>
  
  <p><a href="https://i.stack.imgur.com/yL5xW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yL5xW.png" alt="This is what it looks like"></a></p>
  
  <p>I have added a Pan Gesture Recogniser to the UIView so i can drag it up and down, which works just fine. I have tried to search the internet to find out how I can change the alpha of the green image ONLY inside the UIView rectangle, so that it will look like a window, but without any luck. This is my code so far:</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
  var windowViewOrigin: CGPoint!
  
  @IBOutlet weak var topImageView: UIImageView!
  @IBOutlet weak var bottomImageView: UIImageView!
  @IBOutlet weak var windowView: UIView!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      addPanGesture(view: windowView)
      windowViewOrigin = windowView.frame.origin
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  }
  
  func addPanGesture(view: UIView){
      let pan = UIPanGestureRecognizer(target: self, action: #selector(ViewController.handlePan(sender:)))
      view.addGestureRecognizer(pan)
  }
  
  @objc func handlePan(sender: UIPanGestureRecognizer){
      let window = sender.view!
      let translation = sender.translation(in: view)
  
      switch sender.state {
      case .began, .changed :
          windowView.center = CGPoint(x: UIScreen.main.bounds.size.width*0.5, y: window.center.y + translation.y)
          sender.setTranslation(CGPoint.zero, in: view)
          break
      case .ended:
          UIView.animate(withDuration: 0.5) {
              self.topImageView.alpha = 0.0
          }
          break
      default:
          break
      }
  }
  }
  </code></pre>
  
  <p>I hope someone can help me in the right direction, I have no idea how to move on from this point.</p>