Last active
August 20, 2017 16:12
-
-
Save anirudhamahale/f3c33fe76dcf6fb4809477bf8767f145 to your computer and use it in GitHub Desktop.
Simple code to get the touch event in the UITableView's or UICollectionView's cell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let tap = UITapGestureRecognizer(target: self, action: #selector(self.openWebView(sender:))) | |
| cell.advtImage.isUserInteractionEnabled = true | |
| cell.advtImage.addGestureRecognizer(tap) | |
| func openWebView(sender: UITapGestureRecognizer) { | |
| let tapLocation = sender.location(in: self.collectionView) // Returns the CGPoints of the touched location | |
| if let indexPath = self.collectionView.indexPathForItem(at: tapLocation) // Returns the IndexPath at the above location { | |
| if let cell = self.collectionView.cellForItem(at: indexPath) as? Advertisment2 { | |
| if let url = URL(string: cell.url) { | |
| UIApplication.shared.openURL(url) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment