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