简体   繁体   中英

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

Swift iOS app using UIPanGestureRecognizer:

.state = .Ended is fired when user finishes a pan gesture by lifting the finger off the screen. 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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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