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)
我可能会省略代码的一些细节,但我想知道为什么前一个代码不起作用?显然后者需要更多的代码才能实现这一目标。如何在一个函数中使用UISwipeGestureRecognizer的不同滑动手势方向修复前一个?