简体   繁体   English

Xcode 12 和 iOS 14 中的手势问题

[英]Problem with gesture in Xcode 12 and iOS 14

I have a problem after upgrading to Xcode 12 and iOS 14.升级到 Xcode 12 和 iOS 14 后出现问题。

Scenario: I have a Nested UITableView: nestedTableView .场景:我有一个嵌套的 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.然后我将另一个 UITableView 添加到nestedTableView的 allowGestureEventPassViews 数组中。 so I can control which tableView can be scroll.所以我可以控制哪个 tableView 可以滚动。

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

In Xcode 11.7, iOS 14 worked just fine.在 Xcode 11.7 中,iOS 14 运行良好。

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.但升级到 Xcode 12 后发现手势有所不同。 In Xcode 12 The gesture never pass through the nestedTableView .在 Xcode 12 中,手势永远不会通过nestedTableView

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

Does anyone has the same problem?有没有人有同样的问题? or an I misunderstand something about iOS14 gesture.或者我误解了 iOS14 手势。

I found the answer.我找到了答案。

In iOS14 some reason, UITableViewCellContentView hierarchy is different.由于某些原因,在 iOS14 中, UITableViewCellContentView层次结构是不同的。

In tableView(_:cellForRowAt:) I add subviewtableView(_:cellForRowAt:)我添加子视图

 cell.addSubview(contentScollView)

UITableViewCellContentView is blocking the gesture. UITableViewCellContentView正在阻止手势。

Change to改成

 cell.contentView.addSubview(contentScollView)

This solve my problem.这解决了我的问题。

在目标 C 中:

[self.contentView addSubview: contentScollView];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XCode 12 和 IOS 14 中 UITableView 的问题 - Problem with UITableView in XCode 12 and IOS 14 Xcode 12 和 iOS 14 SDK - Xcode 12 and iOS 14 SDK Xcode 12,iOS 14,吊舱 - Xcode 12, iOS 14, Pods Alignment 在 ios14、xcode12 中不工作 swiftUI - Alignment not working in ios14, xcode12 swiftUI iOS 14 & XCode 12 beta 2 - 从 Firebase 读取数据 - iOS 14 & XCode 12 beta 2 - Reading data from Firebase 在 Xcode 14 - iOS 16 上的 swift/swiftui 中使用 Firestone 获取数据时出现问题 - Problem fetching data with Firestone in swift/swiftui on Xcode 14 - iOS 16 SwiftUI:在尝试构建到 iOS 13 和 iOS 14 时使用 if #available 时出错 - SwiftUI: Error while using if #available while trying to build to iOS 13 and iOS 14 in Xcode 12 beta 2 SwiftUI 在 NavigationView 中添加个人警报视图,后退按钮不适用于 Xcode 12 iOS14 - SwiftUI adding personal alert view in NavigationView, the back button doesn't work with Xcode 12 iOS14 如何将此经典 Swift 线更新为更新的 Swift(与 Xcode 12 和 Z1BDF6059091920DB1EBZCBDF148 正确兼容)? - How to update this classic Swift line to a more recent Swift (compatible with Xcode 12 and iOS 14) properly? Xcode 12 beta 和 iOS 14:奇怪的控制台日志“objc [5551]:Class ...在两者中都实现了” - Xcode 12 beta and iOS 14: Weird console logs "objc[5551]: Class ... is implemented in both"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM