首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不带uigesturerecognizer的ios触摸位置

不带uigesturerecognizer的ios触摸位置
EN

Stack Overflow用户
提问于 2017-08-30 17:41:07
回答 2查看 60关注 0票数 0

如何在没有uigesturerecognizer的情况下在or窗口或uiview上获得触摸位置,目的是在极低的延迟下获得触摸位置,因为调度器可以延迟触摸触发事件

EN

回答 2

Stack Overflow用户

发布于 2017-08-30 17:44:41

您需要创建UIView的子类并覆盖UIResponder (UIView的超类)方法touchesBegan(_:with:)。有关here方法的信息,请参阅文档。

代码语言:javascript
复制
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if let touch = touches.first {
        // Get the touch location in THIS VIEW's coordinate system:
        let locationInThisView = touch.location(in: self)

        // Get the touch location in the WINDOW's coordinate system
        let locationInWindow = touch.location(in: nil)
    }
}

另外,确保您的视图将属性isUserInteractionEnabled设置为true

票数 0
EN

Stack Overflow用户

发布于 2017-08-30 18:04:58

在您的UIView子类中覆盖下面的方法。

代码语言:javascript
复制
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let point =  touches.first?.location(in: self)
    print("location: ", point ?? CGPoint.zero)
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45956981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档