向sceneKit视图添加了按钮,但它有一个滞后

pot*_*ato 8 uibutton ios scenekit

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

     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)

            })
        })
    }
Run Code Online (Sandbox Code Playgroud)

pot*_*ato 6

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

starButton.addTarget(self, action: "starButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)
Run Code Online (Sandbox Code Playgroud)

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