0
    func swipeForMouth(_ recognizer:UISwipeGestureRecognizer) {
    if recognizer.direction == .up{
        expression.mouth = expression.mouth.happierMouth()
    }
    else if recognizer.direction == .down{
        expression.mouth = expression.mouth.sadderMouth()
    }
}//I wanna use this func to draw a MouthView BUT it won't work

//One Practical way to achieve that:
   let happierGesture = UISwipeGestureRecognizer(target: self, action: #selector(FaceViewController.increaseHappiness))
             //There is a "increaseHappiness" func to do such stuff like "expression.mouth = expression.mouth.sadderMouth()"
   happierGesture.direction = .up
   faceView.addGestureRecognizer(happierGesture)
   let sadderGesture = UISwipeGestureRecognizer(target: self, action: #selector(self.decreaseHappiness))
   sadderGesture.direction = .down
   faceView.addGestureRecognizer(sadderGesture)

I may omit some details of the code,but I wonder why the former one just won't work? Obviously the latter one takes more codes to achieve that AND how can I fix the former one using different swiping-gesture directions of UISwipeGestureRecognizer in one func?

Qasa iNto
  • 31
  • 3
  • 1
    This might help you: http://stackoverflow.com/a/24215844/775896 – Mrunal Apr 05 '17 at 12:44
  • 1
    The link @Mrunal gave you is correct. Your issue is not calling the same function, it's that you need to add *two* gestures - one for each direction - and call the function you first tried. –  Apr 05 '17 at 14:49
  • Oh,That really helps! Thanx a lot ! – Qasa iNto Apr 08 '17 at 08:17
  • @dfd your tip sounds nice! I'll be so grateful if you can just give a specific code to do this(I'm totally a beginner) – Qasa iNto Apr 08 '17 at 08:31
  • 1
    I'd like to give you the code, but that link @Mrunal has points you to the best answer I could give. (Currently it has 186 up votes.) Remember: (1) You can only have one direction per *defined* swipe gesture, (2) you can point *all* gestures to the **same** function - in your case, swipeForMouth, which looks coded correctly, except (3) you might want a *switch* statement instead of an *if* (but that will work). –  Apr 08 '17 at 14:46
  • @dfd That link helps a lot ! And I've successfully made my code work ! Thanx again N have a nice day! – Qasa iNto Apr 10 '17 at 13:53

0 Answers0