我假设会有一个内置功能,但我发现只有一个用于轻击手势而不是轻扫手势.
这就是我实现滑动手势的方式:
let gesture = UIPanGestureRecognizer(target: self,action: Selector("wasDragged:")) cardVIEw.addGestureRecognizer(gesture) cardVIEw.userInteractionEnabled = true}func wasDragged (gesture: UIPanGestureRecognizer) { let translation = gesture.translationInVIEw(self.vIEw) let cardVIEw = gesture.vIEw! // Move the object depending on the drag position cardVIEw.center = CGPoint(x: self.vIEw.bounds.wIDth / 2 + translation.x,y: self.vIEw.bounds.height / 2 + translation.y)解决方法 您可以自己创建 UIPanGestureRecognizer并将其传递给wasDragged方法.您应该检查不同的翻译值:
let gesture = UIPanGestureRecognizer()gesture.setTranslation(CGPointMake(0,100),inVIEw: self.vIEw)wasDragged(gesture)
SWIFT 4.2
let gesture = UIPanGestureRecognizer() gesture.setTranslation(CGPoint(x: 0,y: 100),in: self.vIEw) wasDragged(gesture)
虽然我认为你需要别的东西.为什么你需要首先模拟这个手势?
总结以上是内存溢出为你收集整理的ios – 以编程方式模拟Swift中的滑动手势全部内容,希望文章能够帮你解决ios – 以编程方式模拟Swift中的滑动手势所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)