2016-12-31 2 views
1

swview 3アプリケーションにwebview touchイベントを含めるようにしようとしていますが、その間に失敗してしまいます。Swift 3 webview touchイベント

私はグーグルで見つかった例に続いて、toucheBeganとtouchesEndイベントを使用しようとしました。私は

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){ 
    super.touchesBegan(touches, with: event) 
} 

ではなく、作業この方法によりしようとしていますスニペットや迅速な3

とのリンク過去の誰かがすることができます。私はそれにwebviewをどのように統合するのか分かりません。

+0

.. – vaibhav

答えて

2

すべての種類のビューに対してUITapGestureRecognizerを実装することで回避策を試すことができます。

override func viewDidLoad(){ 
    super.viewDidLoad() 
    let tapRecognizer = UITapGestureRecognizer(target: view, action: "handleSingleTap:")  
    tapRecognizer.numberOfTapsRequired = 1     
    self.view.addGestureRecognizer(tapRecognizer) 
} 

func handleSingleTap(recognizer: UITapGestureRecognizer) { 
    //Do something here with the gesture 
} 

タッチの開始とタッチの終了については、ネイティブメソッドをオーバーライドしてそのコードを試してください。

override func touchesBegan(touches: Set, withEvent event: UIEvent) { 
super.touchesBegan(touches, withEvent: event) 
let touch: UITouch = touches.first as! UITouch 
if (touch.view == yourView){ 
    println("touchesBegan | This is an ImageView") 
}else{ 
    println("touchesBegan | This is not an ImageView") 
} 
} 

touchendfunc。あなたが前に試してみましたかを示すことができ

override func touchesEnded(touches: Set, withEvent event: UIEvent) { 
    super.touchesMoved(touches, withEvent: event) 
    let touch: UITouch = touches.first as! UITouch 

    if (touch.view == yourView){ 
     printing("touchesEnded | This is an ImageView") 
    } 
    else{ 
     println("touchesEnded | This is not an ImageView") 
    } 
} 
+0

は私 –

+0

のために働いていなかった私は、plzはあなたがタッチの開始と終了に触れ実装することによって達成するために必要なもの –

+0

コード必ず作品をチェックし、質問を編集しました。 – vaibhav