Unable to add two gesture to a UIView












1















I have a UIView sideMenuView whose child is 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)


When trying to left swipe on goToAccountButton which is a child of sideMenuView, only goToAccountGestureTap works and it doesn't left-swipe at all.



I am unable to understand how to make both UILongPressGestureRecognizer and UIPanGestureRecognizer work on goToAccountButton as expected and so stuck. Please help me find a solution to this. Thank you.










share|improve this question























  • Consider priority based implementation in your multi gesture environment. For more info see developer.apple.com/documentation/uikit/…

    – Ratul Sharker
    Nov 19 '18 at 13:36











  • stackoverflow.com/questions/9272333/…

    – sleepwalkerfx
    Nov 19 '18 at 13:38






  • 2





    increase your minimumPressDuration to 1.0

    – guru
    Nov 19 '18 at 14:28











  • stackoverflow.com/questions/41918256/…

    – Abhijith Purushothaman
    Nov 19 '18 at 15:11
















1















I have a UIView sideMenuView whose child is 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)


When trying to left swipe on goToAccountButton which is a child of sideMenuView, only goToAccountGestureTap works and it doesn't left-swipe at all.



I am unable to understand how to make both UILongPressGestureRecognizer and UIPanGestureRecognizer work on goToAccountButton as expected and so stuck. Please help me find a solution to this. Thank you.










share|improve this question























  • Consider priority based implementation in your multi gesture environment. For more info see developer.apple.com/documentation/uikit/…

    – Ratul Sharker
    Nov 19 '18 at 13:36











  • stackoverflow.com/questions/9272333/…

    – sleepwalkerfx
    Nov 19 '18 at 13:38






  • 2





    increase your minimumPressDuration to 1.0

    – guru
    Nov 19 '18 at 14:28











  • stackoverflow.com/questions/41918256/…

    – Abhijith Purushothaman
    Nov 19 '18 at 15:11














1












1








1








I have a UIView sideMenuView whose child is 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)


When trying to left swipe on goToAccountButton which is a child of sideMenuView, only goToAccountGestureTap works and it doesn't left-swipe at all.



I am unable to understand how to make both UILongPressGestureRecognizer and UIPanGestureRecognizer work on goToAccountButton as expected and so stuck. Please help me find a solution to this. Thank you.










share|improve this question














I have a UIView sideMenuView whose child is 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)


When trying to left swipe on goToAccountButton which is a child of sideMenuView, only goToAccountGestureTap works and it doesn't left-swipe at all.



I am unable to understand how to make both UILongPressGestureRecognizer and UIPanGestureRecognizer work on goToAccountButton as expected and so stuck. Please help me find a solution to this. Thank you.







ios swift xcode






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 12:58









Lesy BancroftLesy Bancroft

63




63













  • Consider priority based implementation in your multi gesture environment. For more info see developer.apple.com/documentation/uikit/…

    – Ratul Sharker
    Nov 19 '18 at 13:36











  • stackoverflow.com/questions/9272333/…

    – sleepwalkerfx
    Nov 19 '18 at 13:38






  • 2





    increase your minimumPressDuration to 1.0

    – guru
    Nov 19 '18 at 14:28











  • stackoverflow.com/questions/41918256/…

    – Abhijith Purushothaman
    Nov 19 '18 at 15:11



















  • Consider priority based implementation in your multi gesture environment. For more info see developer.apple.com/documentation/uikit/…

    – Ratul Sharker
    Nov 19 '18 at 13:36











  • stackoverflow.com/questions/9272333/…

    – sleepwalkerfx
    Nov 19 '18 at 13:38






  • 2





    increase your minimumPressDuration to 1.0

    – guru
    Nov 19 '18 at 14:28











  • stackoverflow.com/questions/41918256/…

    – Abhijith Purushothaman
    Nov 19 '18 at 15:11

















Consider priority based implementation in your multi gesture environment. For more info see developer.apple.com/documentation/uikit/…

– Ratul Sharker
Nov 19 '18 at 13:36





Consider priority based implementation in your multi gesture environment. For more info see developer.apple.com/documentation/uikit/…

– Ratul Sharker
Nov 19 '18 at 13:36













stackoverflow.com/questions/9272333/…

– sleepwalkerfx
Nov 19 '18 at 13:38





stackoverflow.com/questions/9272333/…

– sleepwalkerfx
Nov 19 '18 at 13:38




2




2





increase your minimumPressDuration to 1.0

– guru
Nov 19 '18 at 14:28





increase your minimumPressDuration to 1.0

– guru
Nov 19 '18 at 14:28













stackoverflow.com/questions/41918256/…

– Abhijith Purushothaman
Nov 19 '18 at 15:11





stackoverflow.com/questions/41918256/…

– Abhijith Purushothaman
Nov 19 '18 at 15:11












1 Answer
1






active

oldest

votes


















0














As @Ratul Sharker was hinting at, you need to make one of the gestures take priority. You probably want the pan to take priority, so add



goToAccountGestureTap.require(toFail: leftPanSwipe)


after you've set up the long-press gesture. This way, the long-press will only be checked for if the gesture isn't recognized as a pan gesture.






share|improve this answer
























  • Mentioning this makes goToAccountGestureTap not work at all. How should I improve this?

    – Lesy Bancroft
    Nov 20 '18 at 5:52











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375164%2funable-to-add-two-gesture-to-a-uiview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














As @Ratul Sharker was hinting at, you need to make one of the gestures take priority. You probably want the pan to take priority, so add



goToAccountGestureTap.require(toFail: leftPanSwipe)


after you've set up the long-press gesture. This way, the long-press will only be checked for if the gesture isn't recognized as a pan gesture.






share|improve this answer
























  • Mentioning this makes goToAccountGestureTap not work at all. How should I improve this?

    – Lesy Bancroft
    Nov 20 '18 at 5:52
















0














As @Ratul Sharker was hinting at, you need to make one of the gestures take priority. You probably want the pan to take priority, so add



goToAccountGestureTap.require(toFail: leftPanSwipe)


after you've set up the long-press gesture. This way, the long-press will only be checked for if the gesture isn't recognized as a pan gesture.






share|improve this answer
























  • Mentioning this makes goToAccountGestureTap not work at all. How should I improve this?

    – Lesy Bancroft
    Nov 20 '18 at 5:52














0












0








0







As @Ratul Sharker was hinting at, you need to make one of the gestures take priority. You probably want the pan to take priority, so add



goToAccountGestureTap.require(toFail: leftPanSwipe)


after you've set up the long-press gesture. This way, the long-press will only be checked for if the gesture isn't recognized as a pan gesture.






share|improve this answer













As @Ratul Sharker was hinting at, you need to make one of the gestures take priority. You probably want the pan to take priority, so add



goToAccountGestureTap.require(toFail: leftPanSwipe)


after you've set up the long-press gesture. This way, the long-press will only be checked for if the gesture isn't recognized as a pan gesture.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 15:35









NRitHNRitH

7,68222733




7,68222733













  • Mentioning this makes goToAccountGestureTap not work at all. How should I improve this?

    – Lesy Bancroft
    Nov 20 '18 at 5:52



















  • Mentioning this makes goToAccountGestureTap not work at all. How should I improve this?

    – Lesy Bancroft
    Nov 20 '18 at 5:52

















Mentioning this makes goToAccountGestureTap not work at all. How should I improve this?

– Lesy Bancroft
Nov 20 '18 at 5:52





Mentioning this makes goToAccountGestureTap not work at all. How should I improve this?

– Lesy Bancroft
Nov 20 '18 at 5:52




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375164%2funable-to-add-two-gesture-to-a-uiview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()