2016-05-12 62 views
3

我正在研究iOS的鍵盤擴展。不過,我在動畫/圖層中出現了一些奇怪的問題,它們並未立即出現在屏幕的最左側。當用戶按下某個鍵時,我使用圖層/動畫顯示「工具提示」。對於除A和Q以外的所有按鍵,都會立即顯示工具提示,但對於這兩個按鍵,在出現圖層和動畫之前似乎會有一些延遲。這隻會在接觸時發生,如果我滑入Q或A擊中區域,工具提示會立即呈現。我的調試顯示代碼對所有的鍵執行完全一樣,但對於這兩個鍵,它不會立即生效。iOS鍵盤擴展中的屏幕左側的動畫延遲

任何有關是否有可能導致此行爲的屏幕左邊緣有什麼特別的想法?還是我在做一些愚蠢的事情呢?

這是我的觸摸處理代碼部觸發刀尖渲染:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 
    if(!shouldIgnoreTouches()) { 
     for touch in touches { 
      let location = (touch).locationInView(self.inputView) 

      // pass coordinates to offset service to find candidate keys 
      let keyArray = keyOffsetService.getKeys(_keyboardLayout!, location: location) 
      let primaryKey = keyArray[0] 

      if primaryKey.alphaNumericKey != nil { 
       let layers = findLayers(touch) 

       if layers.keyLayer != nil { 
        graphicsService.animateKeyDown(layers.keyLayer as! CATextLayer, shieldLayer: layers.shieldLayer) 
        _shieldsUp.append((textLayer:layers.keyLayer, shieldLayer:layers.shieldLayer)) 
       } 
      } 
     } 
    } 
} 

動畫代碼:

func animateKeyDown(layer:CATextLayer, shieldLayer:CALayer?) { 
    if let sLayer = shieldLayer { 
     keyDownShields(layer, shieldLayer: sLayer) 
     CATransaction.begin() 
     CATransaction.setDisableActions(true) 

     let fontSizeAnim = CABasicAnimation(keyPath: "fontSize") 
     fontSizeAnim.removedOnCompletion = true 
     fontSizeAnim.fromValue = layer.fontSize 
     fontSizeAnim.toValue = layer.fontSize * 0.9 
     layer.fontSize = layer.fontSize * 0.9 

     let animation = CABasicAnimation(keyPath: "opacity") 
     animation.removedOnCompletion = true 
     animation.fromValue = layer.opacity 
     animation.toValue = 0.3 
     layer.opacity = 0.3 

     let animGroup = CAAnimationGroup() 
     animGroup.animations = [fontSizeAnim, animation] 
     animGroup.duration = 0.01 
     layer.addAnimation(animGroup, forKey: "down") 

     CATransaction.commit() 
    } 
} 

取消隱藏工具提示層:

private func keyDownShields(layer:CATextLayer, shieldLayer:CALayer) { 
    shieldLayer.hidden = false 
    shieldLayer.setValue(true, forKey: "isUp") 
    shieldLayer.zPosition = 1 
    shieldLayer.removeAllAnimations() 
    layer.setValue(true, forKey: "isUp") 
} 

Image of the keyboard with tooltip

回答

2

這是由iOS 9中的一項功能引起的,該功能允許用戶在向右滑動時強制按屏幕左邊緣切換應用程序。

您可以通過禁用3D touch來關閉此功能,但這不是一個解決方案。

我不知道有任何API可以讓您覆蓋此行爲。

+0

謝謝,這是有道理的。我猜想iOS10的行爲發生了變化,因爲問題已經消失了。 – Malakim

+0

我的iPhone 6s iOS 11版本仍然存在這個問題任何想法如何禁用我的應用程序內的3D觸摸? – Netero

+0

@Netero,據我所知 - 你不能。至少我們從來沒有做過任何事情。 – Malakim