iOS按钮与自定义键盘上的边缘手势冲突

问题描述 投票:0回答:1

我的自定义键盘上的按钮在屏幕的左侧和右侧具有.touchdown操作。当我单击它们时,他们没有立即注册.touchdown,似乎正在等待查看是否有滑动手势。我尝试使用代码来推迟边缘手势,但是在iOS 13中,这似乎并没有解决问题。有没有人有解决方案,如何使单击按钮时边缘的按钮立即执行.touchdown操作?]

override var preferredScreenEdgesDeferringSystemGestures: UIRectEdge {
    return [.left, .bottom, .right]
}

我也尝试过在自定义按钮类中使用point函数,但这只会使其突出显示,但仍然无法立即执行操作。

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    let inside = super.point(inside: point, with: event)

    if inside && !isHighlighted && event?.type == .touches {
        isHighlighted = inside
    }

    return bounds.insetBy(dx: -2.7, dy: -12).contains(point)
}
ios xcode keyboard uigesturerecognizer
1个回答
0
投票
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    if let window = view.window,
        let recognizers = window.gestureRecognizers {
        recognizers.forEach { r in
            r.delaysTouchesBegan = false
            r.cancelsTouchesInView = false
            r.isEnabled = false
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.