Animation delay on left side of screen in iOS keyboard extension

放肆的年华 提交于 2019-12-12 13:19:03

问题


I'm working on a keyboard extension for iOS. However, I'm having some weird issues with animations / layers not appearing instantly on the far left of the screen. I use layers / animations to show a "tool tip" when the user presses a key. For all keys except A and Q the tool tips are displayed instantly, but for these two keys there seems to be a slight delay before the layer and animation appears. This only happens on touch down, if I slide into the Q or A hit area the tool tips gets rendered instantly. My debugging shows that the code executes exactly the same for all keys, but for these two keys it has no immediate effect.

Any ideas on if there's anything special with the left edge of the screen that might cause this behaviour? Or am I doing something stupid that might be the cause of this?

This is part of my touch handling code that triggers the tool tip rendering:

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))
                }
            }
         }
    }
}

animation code:

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()
    }
}

unhide tooltip layer:

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")
}


回答1:


This is caused by a feature in iOS 9 which allows the user to switch apps by force pressing the left edge of the screen while swiping right.

You can turn this off by disabling 3D touch but this is hardly a solution.

I am not aware of any API that allows you to override this behavior.



来源:https://stackoverflow.com/questions/37196205/animation-delay-on-left-side-of-screen-in-ios-keyboard-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!