Problem with gesture in Xcode 12 and iOS 14

痴心易碎 提交于 2021-01-21 13:48:55

问题


I have a problem after upgrading to Xcode 12 and iOS 14.

Scenario: I have a Nested UITableView: nestedTableView. Like below

class GAllowGestureEventPassTableView: UITableView, UIGestureRecognizerDelegate {

    var allowGestureEventPassViews: [UIView] = []
    
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        panGestureRecognizer.cancelsTouchesInView = false
        guard let otherView = otherGestureRecognizer.view else { return false }
        print("tableView 💙 : \(type(of: otherView))")
        if allowGestureEventPassViews.contains(otherView) {
            print("allowGestureEventPassViews contains 💙 : \(type(of: otherView))")
            print("gesture pass 💙 ")
            return true
        } else {
            return false
        }
    }
}

Then I add another UITableView to nestedTableView's allowGestureEventPassViews array. so I can control which tableView can be scroll.

    self.nestedTableView.allowGestureEventPassViews.append(controller.tableView)

In Xcode 11.7, iOS 14 worked just fine.

Log:

tableView 💙 : GAllowGestureEventPassTableView
tableView 💙 : GAllowGestureEventPassTableView
tableView 💙 : GAllowGestureEventPassTableView
tableView 💙 : UITableView
allowGestureEventPassViews contains 💙 : UITableView
gesture pass 💙 

but after upgrading to Xcode 12 gesture seen to be different. In Xcode 12 The gesture never pass through the nestedTableView.

tableView 💙 : GAllowGestureEventPassTableView
tableView 💙 : GAllowGestureEventPassTableView
tableView 💙 : GAllowGestureEventPassTableView
tableView 💙 : UITableViewCellContentView

Does anyone has the same problem? or an I misunderstand something about iOS14 gesture.


回答1:


I found the answer.

In iOS14 some reason, UITableViewCellContentView hierarchy is different.

In tableView(_:cellForRowAt:) I add subview

 cell.addSubview(contentScollView)

UITableViewCellContentView is blocking the gesture.

Change to

 cell.contentView.addSubview(contentScollView)

This solve my problem.



来源:https://stackoverflow.com/questions/63987896/problem-with-gesture-in-xcode-12-and-ios-14

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!