Guest User

Untitled

a guest
Sep 4th, 2017
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
  2.   if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {
  3. let translation = panGestureRecognizer.translation(in: superview)
  4. if fabs(translation.x) > fabs(translation.y) {
  5. return true
  6. }
  7. return false
  8. }
  9. return false
  10. }
  11.  
  12. var table = UITableView()
  13.  
  14. extension ViewController: UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate {
  15.  
  16. func equipList(_ notification: Notification) {
  17.  
  18. //テーブル設定(省略)
  19.  
  20. table.delegate = self
  21. table.dataSource = self
  22.  
  23. let pan = UIPanGestureRecognizer(target: self, action: #selector(pan(_:)))
  24. pan.delegate = self
  25. table.addGestureRecognizer(pan)
  26.  
  27. self.view.addSubview(table)
  28.  
  29. }
  30.  
  31. @objc(tableView:cellForRowAtIndexPath:) func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  32. var cell = UITableViewCell()
  33.  
  34. //セル設定(省略)
  35.  
  36. return cell
  37. }
  38. func tableView(_ tableView: UITableView, numberOfSection section: Int) -> Int {
  39. return 0
  40. }
  41. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  42. return 100
  43. }
  44. }
  45.  
  46. extension UITableView {
  47. open override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
  48. print(gestureRecognizer)
  49. if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {
  50. let translation = panGestureRecognizer.translation(in: table)
  51. if fabs(translation.x) > fabs(translation.y) {
  52. print("A")
  53. return true
  54. }
  55. print("B")
  56. return false
  57. }
  58. print("C")
  59. return false
  60. }
  61. }
  62. }
  63.  
  64. extension UITableView {
  65.  
  66. extension ViewController: UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate {
  67.  
  68. extension ViewController: UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate {
  69. func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
  70. if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {
  71. let translation = panGestureRecognizer.translation(in: panGestureRecognizer.view)
  72. if fabs(translation.x) > fabs(translation.y) {
  73. return true
  74. }
  75. return false
  76. }
  77. return false
  78. }
  79.  
  80. ・・・
Advertisement
Add Comment
Please, Sign In to add comment