快速运行一次翻译条件

时间:2019-04-05 14:38:18

标签: ios swift

我创建了一个UIView和一个位于UIImageView内部的UIView作为子视图,然后我向UIImageView添加了一个平移手势以在{{ 1}},图像现在开始滑动,但是现在的问题是,当滑块到达视图UIView的末端时,我只想if movex > xMax打印一次。只要用户没有从用来滑动的print("SWIPPERD movex")上移开他/她的手,我在那里的当前代码就会继续打印print("SWIPPERD movex")

UIImageView

1 个答案:

答案 0 :(得分:0)

You may want to use the .ended state instead of .changed state, based on your requirements. And you've mentioned you want to get the right direction only. You could try below to determine if the swipe came from right to left, or vice-versa, change as you wish:

let velocity = sender.velocity(in: sender.view)
let rightToLeftSwipe = velocity.x < 0