简体   繁体   English

Swift:UIPanGestureRecognizer如何判断是否在屏幕外使用了拖曳的手指

[英]Swift: UIPanGestureRecognizer How to tell if use dragged finger outside screen

Swift iOS app using UIPanGestureRecognizer: 使用UIPanGestureRecognizer的Swift iOS应用程序:

.state = .Ended is fired when user finishes a pan gesture by lifting the finger off the screen. 当用户通过将手指抬离屏幕完成平移手势时,将触发.state = .Ended This is successful pan for me. 这对我来说是成功的锅。

However, the same happens when the user drags their finger off the screen, which is an unsuccessful pan for me but how to distinguish it from the former? 但是,当用户将手指从屏幕上拖出时,也会发生同样的情况,这对我来说是不成功的平移,但是如何与前者区分开呢?

You can't distinguish between the gesture ending because the user lifted the finger and the gesture ending because the finger went off the edge of the screen. 您无法区分由于用户抬起手指而导致的手势结束和因手指离开屏幕边缘而导致的手势结束。 You've already deduced that, quite correctly. 您已经很正确地推断出这一点。 So you will have to settle for what you can do. 因此,您将不得不满足于自己的能力

When the gesture ends, look at the location of the finger. 手势结束后,查看手指的位置。 (The gesture recognizer will happily tell you this.) If it's at the edge of the screen, or perhaps even within a couple of points of the edge of the screen, you'll just have to assume arbitrarily that this means the user dragged "out of bounds". (手势识别器会很乐意告诉您。)如果它位于屏幕边缘,或者甚至在屏幕边缘的两个点之内,您只需任意假设这意味着用户拖动了“越界”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM