【问题标题】:iOS: Why touchesBegan has some delay in some specific area in UIViewiOS:为什么 touchesBegan 在 UIView 的某些特定区域有一些延迟
【发布时间】:2016-02-17 02:16:02
【问题描述】:

我正在制作一个自定义键盘,但我的情况非常奇怪。

我注意到,当我在 UIView (inputView) 的左后角(大约 20 像素)捕捉到事件 touchesBegan 时,我会在这里有一些延迟。 我在 touchesBegan 中执行的任何操作都会比其他区域执行得慢。

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
{
self.keypop.hidden = false
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
{
self.keypop.hidden = true
}

而且这个问题会影响我的应用程序的性能。 在这个例子中,当我触摸左后方时,我不会看到弹出键出现,因为self.keypop.hidden 出现延迟。

我不知道为什么,或者这是 iOS 9 的错误? 我已经被这个问题困扰了一个星期了。

【问题讨论】:

    标签: ios swift delay touchesbegan


    【解决方案1】:

    在我的情况下,我在 CollectionView 中使用 touchBegan,当我点击时它会延迟触摸 只需添加此代码即可与我合作

    在 Swift 中,

    self.collectionView.delaysContentTouches = false
    /*delaysContentTouches applies to all UIScrollView instances.*/
    

    【讨论】:

      【解决方案2】:

      这里的答案似乎已经解决了我们键盘中的相同问题:

      UISystemGateGestureRecognizer and delayed taps near bottom of screen

      使用以下代码:

      override func viewDidAppear(animated: Bool) {
          let window = view.window!
          let gr0 = window.gestureRecognizers![0] as UIGestureRecognizer
          let gr1 = window.gestureRecognizers![1] as UIGestureRecognizer
          gr0.delaysTouchesBegan = false
          gr1.delaysTouchesBegan = false
      }
      

      【讨论】:

      • 这救了我的命!我在使用 SpriteKit 应用程序时遇到这个问题已经有一段时间了,有时我需要在屏幕的顶部和底部做一些事情,但它总是有奇怪的行为。
      • 这可行,但如果您使用手势识别器,它们似乎可以正常工作。对我来说(我希望触地工作的 SpriteKit 游戏),我使用了一个长按,最小持续时间设置为 0,并在 state.began 上触发。来自stackoverflow.com/a/38143619/3937的技术
      猜你喜欢
      • 1970-01-01
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      • 2016-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多