是否有一种方法/类可以检测手指从一侧滑出屏幕时是否离开屏幕?
谢谢。
最佳答案
您可以尝试使用 touchesEnded 来检测触摸结束时手指的位置。如果在屏幕边的边缘,可以推断用户已经离开了屏幕。
所以在 iPhone 上,如果它是左侧或右侧,它的 x 坐标将为 0 或 320,如果它是顶部和底部,它的 y 坐标将为 0 或 480。 在 iPad 上,它分别是 0 和 768,以及 0 和 1024。
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
您可以从 touchesBegan 开始并检测它们来自哪个方向,以决定向哪个方向滑动屏幕。
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
touchesBegan 和 touchesEnded 是 UIResponder 类的方法,因此它应该可以在任何地方免费使用。
关于iOS : detecting finger leaving the screen on the sides ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10739307/