iOS键盘扩展中屏幕左侧的动画延迟 [英] Animation delay on left side of screen in iOS keyboard extension

查看:79
本文介绍了iOS键盘扩展中屏幕左侧的动画延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iOS扩展键盘。但是,我遇到了一些动画/图层无法立即显示在屏幕最左边的怪异问题。当用户按下一个键时,我使用图层/动画来显示工具提示。对于除A和Q以外的所有关键点,工具提示都会立即显示,但是对于这两个关键点,似乎在图层和动画出现之前会稍有延迟。这仅在触地时发生,如果我滑到Q或A命中区域,工具提示将立即呈现。我的调试显示,代码对所有键的执行完全相同,但是对于这两个键,它没有立即生效。

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

动画代码:

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

推荐答案

这是由iOS 9中的一项功能引起的,该功能允许用户通过在向右滑动时强行按下屏幕的左边缘来切换应用。

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.

您可以通过禁用3D触摸来关闭此功能,但这几乎不是解决方案。

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

我不知道有哪个API允许您覆盖此行为。

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

这篇关于iOS键盘扩展中屏幕左侧的动画延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆