添加按钮到sceneKit视图但它有一个滞后 [英] added button to sceneKit view but it has a lag

查看:86
本文介绍了添加按钮到sceneKit视图但它有一个滞后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sceneKit视图中添加了一个自定义按钮。触摸时,它会播放动画,表示已单击。我面临的问题是用户触摸和动画开始之间的延迟。我的场景有28.1K三角形和84.4K顶点。是那么多,还是我需要以不同的方式实现按钮。场景渲染为60fps。我通过 sceneView.addSubview添加了按钮:感谢您的答案

I added a custom button to the sceneKit view. When it is touched, it plays an animation, indicating that it was clicked. The problem I'm facing is the delay between user touch and start of animation. My scene has 28.1K triangles and 84.4K vertices. Is that to much or do I need to implement buttons differently. The scene renders with 60fps. I added the button via sceneView.addSubview: Thanks for answers

     viewDidLoad(){
     // relevant code
        starButton = UIButton(type: UIButtonType.Custom)
        starButton.frame = CGRectMake(100, 100, 50, 50)
        starButton.setImage(UIImage(named: "yellowstar.png"), forState: UIControlState.Normal)
        sceneView.addSubview(starButton)
        starButton.addTarget(self, action: "starButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)
        starButton.adjustsImageWhenHighlighted = false
        }



    func starButtonClicked(){
            animateScaleDown()

        }

    func animateScaleDown(){

        UIView.animateWithDuration(0.1, animations: {
            self.starButton.transform = CGAffineTransformMakeScale(0.8, 0.8)

            }, completion: { _ in
                self.wait()
        })

    }

    func wait(){
        UIView.animateWithDuration(0.2, animations: {}, completion: { _ in
            UIView.animateWithDuration(0.2, animations: {
                self.starButton.transform = CGAffineTransformMakeScale(1, 1)

            })
        })
    }


推荐答案

好的,我解决了。有问题的代码是

Okay I solved it. The problematic piece of code is

starButton.addTarget(self, action: "starButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)

UIControlEvent.TouchUpInside 给出了滞后的错觉。将其更改为 .TouchDown 要好得多。

UIControlEvent.TouchUpInside gives the illusion of lag. Changing it to .TouchDown is much better.

这篇关于添加按钮到sceneKit视图但它有一个滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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