title: Swift - Add UIImageView as subview of UIWebView scrollView and scaling
body: <p>I have a <code>UIWebView</code> and I have successfully added a <code>UIImage</code> view to the <code>UIWebView</code>’s <code>scrollView</code> like so:</p>
  
  <pre><code>let localUrl = String(format:"%@/%@", PDFFilePath, fileNameGroup)
          let url = NSURL.fileURLWithPath(localUrl)
  
          panRecognizer = UITapGestureRecognizer(target: self, action: #selector(panDetected))
          pinchRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(pinchDetected))
  
          panRecognizer.delegate = self
          pinchRecognizer.delegate = self
  
          webview = UIWebView()
          webview.frame = self.view.bounds
          webview.scrollView.frame = webview.frame
  
          webview.userInteractionEnabled = true
          webview.scalesPageToFit = true
          webview.becomeFirstResponder()
          webview.delegate = self
          webview.scrollView.delegate = self
          self.view.addSubview(webview)
          webview.loadRequest(NSURLRequest(URL:url))
          webview.gestureRecognizers = [pinchRecognizer, panRecognizer]
  
  let stampView:StampAnnotation = StampAnnotation(imageIcon: UIImage(named: "approved.png"), location: CGPointMake(currentPoint.x, currentPoint.y))
              self.webview.scrollView.addSubview(stampView)
  </code></pre>
  
  <p>My <code>UIWebView</code> <code>scrollView</code> is scalable. Now I am looking for away to have my <code>UIImageView</code> (<code>StampAnnotation</code> is a class and <code>UIImageView</code> is its subclass) scale when the <code>scrollView</code> scales. So if the user zooms in on the <code>scrollView</code>, the <code>UIImageView</code> will get bigger and stay in a fixed position and if the user zooms out, the <code>UIImageView</code> will get smaller while the <code>scrollView</code> gets smaller while staying in a fixed position.</p>
  
  <p>I really hope that makes sense. I have tried the following:</p>
  
  <pre><code>func pinchDetected(recognizer:UIPinchGestureRecognizer)
      {
  
          for views in webview.scrollView.subviews
          {
              if(views.isKindOfClass(UIImageView))
              {
                  views.transform = CGAffineTransformScale(views.transform, recognizer.scale, recognizer.scale)
                  recognizer.scale = 1
              }
          }
  
          if(appDelegate.annotationSelected == 0)
          {
              webview.scalesPageToFit = true
          }
          else
          {
              webview.scalesPageToFit = false
          }
  
      }
  </code></pre>
  
  <p>but this does nothing, if I remove this line:</p>
  
  <pre><code>recognizer.scale = 1
  </code></pre>
  
  <p>it scales way too big too fast. My question is, how do I get my <code>UIImageView</code> to scale when the <code>UIWebview</code>’s <code>scrollView</code> scrolls?</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>This solved my problem.</p>
  
  <pre><code>func scrollViewDidZoom(scrollView: UIScrollView) {
  
      for views in webview.scrollView.subviews
      {
          if(views.isKindOfClass(UIImageView))
          {
              views.transform = CGAffineTransformMakeScale(scrollView.zoomScale, scrollView.zoomScale)
          }
      }
  
  }
  </code></pre>
  
  <p>No it does not stay in a fixed position on the page, but I think that is a constraints issue?</p>