美文网首页
2018-03-07

2018-03-07

作者: 依兰索亚 | 来源:发表于2018-03-07 12:58 被阅读0次

    一、gesture与tableView手势冲突,didSelectRowAtIndexPath:执行出问题

    1、ViewController作为rootViewController,中使用了手势,导致其他页面中tableView,didSelectRowAtlndexpath点击无响应

    2、解决方法:

    (1)、设置手势的代理为self, 并在ViewController加入UIGestureRecognizerDelegate

    (2)、调用 func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool方法

    代码如下:

    class ViewController: UIViewController,UIGestureRecognizerDelegate {

        override func viewDidLoad() {

            super.viewDidLoad()

            //单击收起菜单手势

            let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture))

            tapGestureRecognizer.delegate = self

            self.view.addGestureRecognizer(tapGestureRecognizer)

        }

        //单击手势响应

        @objc func handleTapGesture() {

            //如果菜单是展开的点击主页部分则会收起

            if currentState == .Expanded {

                animateMainView(false)

            }

        }

        func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {

            print(NSStringFromClass((touch.view?.classForCoder)!))

            if NSStringFromClass((touch.view?.classForCoder)!) == "UITableViewCellContentView"{

                return false

            }

            return true

        }

    相关文章

      网友评论

          本文标题:2018-03-07

          本文链接:https://www.haomeiwen.com/subject/nldjfftx.html