iOS : detecting finger leaving the screen on the sides ?

标签 ios uiviewcontroller

是否有一种方法/类可以检测手指从一侧滑出屏幕时是否离开屏幕?

谢谢。

最佳答案

您可以尝试使用 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/

相关文章:

Swift - 将 ViewController 插入会出现黑屏

ios - 根据从 xib 文件加载的 subview 调整 UIView 的大小

objective-c - 重新加载 View Controller 后自动旋转不起作用

ios - 没有收到大于 256 字节的推送通知 iOS 8

iphone - iOS设备硬件修订号列表

ios - Swift UIPageViewController 和 UIActivityIndi​​catorView

ios - 使用 performSelectorOnMainThread iOS 在调用中转换对象

ios - PerformSegueWithIdentifier 和 rootViewController 的问题

iOS 如何从 UIViewController 访问 UIView 属性

ios - 在不旋转的情况下应用透视变换