簡體   English   中英

無法向UIView添加兩個手勢

[英]Unable to add two gesture to a UIView

我有一個UIView sideMenuView其子級為UIView goToAccountButton

let leftPanSwipe = UIPanGestureRecognizer(target: self, action: #selector(self.sideMenuTranslate))
sideMenuView.addGestureRecognizer(leftPanSwipe)

let goToAccountGestureTap = UILongPressGestureRecognizer(target: self, action: #selector(self.goToAccountGesture))
goToAccountGestureTap.minimumPressDuration = 0.0
goToAccountButton.addGestureRecognizer(goToAccountGestureTap)

當嘗試在goToAccountButton的子項的sideMenuView上向左滑動時,僅goToAccountGestureTap有效,並且根本不向左滑動。

我無法理解如何按預期使UILongPressGestureRecognizerUIPanGestureRecognizergoToAccountButtongoToAccountButton工作,因此卡住了。 請幫助我找到解決方案。 謝謝。

正如@Ratul Sharker所暗示的那樣,您需要使其中一個手勢優先。 您可能希望平移鍋優先,所以添加

goToAccountGestureTap.require(toFail: leftPanSwipe)

設置長按手勢后。 這樣,只有在未將手勢識別為平移手勢時才檢查長按。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM