View Hierarchy with transparent UIView to pass through touch event's issue?

Here is my hierarchy;

Here is my code;

    class ViewControllerTabOne: TabViewController, WKNavigationDelegate
 {
     @IBOutlet weak var glassView: UIView!
    @IBOutlet weak var responseWebView: WKWebView!
    
    var portionRect: CGRect!
     
     override func viewDidLoad()
     {
         super.viewDidLoad()
         
         self.view.isUserInteractionEnabled = true
        
         self.responseWebView!.navigationDelegate = self

        loadWebsite()

         // Do any additional setup after loading the view.
    }
     
func loadWebsite()
 {
     self.urlReq = URLRequest(url: URL(string: "https://www.google.com/")!)
      self.responseWebView.load(self.urlReq!)
}

     func simulateTap()
     {
         let pointOnTheScreen = CGPoint(x: 156.0, y: 506.6)
         self.glassView.hitTest(pointOnTheScreen, with: nil)
        self.glassView.overlapHitTest(point: pointOnTheScreen, withEvent: nil)
          print("tap on screen")
    }
     
     override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
     {
         if let touch = touches.first
         {
             let touchLocation = touch.location(in: self.view)
             print("point touched: \(touchLocation)")
         }
         super.touchesBegan(touches, with:event)
     }
     
 func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)
 {
     print("Finished navigating to url \(String(describing: webView.url))")
     
    self.simulateTap()
 }

     /*
     // MARK: - Navigation
 
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
         // Get the new view controller using segue.destination.
         // Pass the selected object to the new view controller.
     }
    */
 
 }
 
extension UIView
 {    
     func overlapHitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView?
     {
         // 1
         if !self.isUserInteractionEnabled || self.isHidden || self.alpha == 0
         {
             return nil
         }
         //2
        var hitView: UIView? = self
         if !self.point(inside: point, with: event)
         {
             if self.clipsToBounds
             {
                 return nil
             }
             else
              {
                 hitView = nil
             }
         }
         //3
         for subview in self.subviews.reversed()
         {
             let insideSubview = self.convert(point, to: subview)
             if let sview = subview.overlapHitTest(point: insideSubview, withEvent: event)
             {
                 return sview
             }
         }
         return hitView
     }
 }
 
 class PassThroughView: UIView {
     override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
         for subview in subviews {
             if !subview.isHidden && subview.isUserInteractionEnabled && subview.point(inside: convert(point, to: subview), with: event) {
                 return true
             }
         }
         return false
     }
     
     override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
         let view = super.hitTest(point, with: event)
         if view == self {
             return nil //avoid delivering touch events to the container view (self)
         } else {
             return view //the subviews will still receive touch events
         }
     }
 }

Essentially, I have the GlassView OVER the Web View and I want to be able to interact with the Web View as if there is nothing over it while being able to simulate a tap on a webview button while being able to see its x and y coordinates of a tap (so i can automate a process on a webview)

Mind you that it is all within a TABBARCONTROLLER

I need to be able to send through touch events to record the locations and then simulate touch events on the wkwebview

Current code is able to interact with wkwebview as if glassview is not over it, but the simulatetap function does nothing and i do not see touchesbegan fire off with locations.

I am referencing;

This isn't about Swift the language, it's about the Apple frameworks. The question applies equally if you were to use Objective-C instead of Swift. Probably better to keep asking over at StackOverflow, or the Apple Developer forums.

Then why are other people posting code snippets if it ain't bout the language?

Terms of Service

Privacy Policy

Cookie Policy