-1

I have created a UI Image view. Is it possible for the user to click on the UI Image view and have the link pop up? If so how would I go about incorporating that? I was thinking possibly through my View Controller using Touches Began and then specifically with a tag, but I'm using Swift's Game View Controller so the Touches Began function is not working properly and won't allow me to convert my SKNODE to Game View Controller type. Any suggestions on how you would do this? Thanks

crocs123
  • 67
  • 6

3 Answers3

1

You are going to want to look at UITapGestureRecognizer. Here is an example below.

if let imageView = yourImageView {
let tap = UITapGestureRecognizer(target: self, action: #selector(self.openLink(_:)))
    imageView.addGestureRecognizer(tap)
}

Here is a link if you are also wondering how to open a link in safari.

Swift Open Link in Safari

gmdev
  • 2,725
  • 2
  • 13
  • 28
Nathan Walsh
  • 358
  • 2
  • 4
0

I just used a gesture recognizer and it worked perfectly

crocs123
  • 67
  • 6
0

Check out this :

 let recognizer = UITapGestureRecognizer(target: self, action: #selector(webViewTapped))
    recognizer.delegate = self
    webView.addGestureRecognizer(recognizer)

and :

    @objc func webViewTapped(_ recognizer: UITapGestureRecognizer) {
    if let selectedWebView = recognizer.view as? WKWebView {
        selectWebView(selectedWebView)
    }
}
   func selectWebView(_ webView: WKWebView) {
 
     activeWebView = webView

     updateUI(for: webView)
}
roadRunner
  • 173
  • 1
  • 23