Прозрачный UIView поверх WKWebview для прохождения сенсорных событий - PullRequest
0 голосов
/ 11 февраля 2020

Вот моя иерархия;

enter image description here

Вот мой код;

    class ViewControllerTabOne: TabViewController, WKNavigationDelegate
{
    @IBOutlet weak var glassView: UIView!
    @IBOutlet weak var yeezySupplyWebView: WKWebView!

    var portionRect: CGRect!

    override func viewDidLoad()
    {
        super.viewDidLoad()

        self.view.isUserInteractionEnabled = true

        // Do any additional setup after loading the view.
    }

    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)
    }

    /*
    // 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
        }
    }
}

По сути, у меня есть GlassView OVER веб-представление, и я хочу иметь возможность взаимодействовать с веб-представлением, как если бы над ним ничего не было.

Имейте в виду, что все это в TABBARCONTROLLER

Мне нужно иметь возможность отправлять через сенсорные события для записи местоположений, а затем моделировать сенсорные события в wkwebview

Текущий код может отслеживать x и y шнуры сенсорного события, но я не могу взаимодействовать с wkwebview (перетащите, или коснитесь).

Я ссылаюсь;

Как я могу нажать кнопку за прозрачным UIView?

Swift - программно нажать в точке на экране

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...