【发布时间】:2015-10-09 11:36:16
【问题描述】:
我在 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)
})
})
}
【问题讨论】:
-
能贴一下触摸和动画代码吗?
-
我编辑了我的问题
-
延迟多少?如果您非常敏感,您可能会在动画开始之前看到 SDK 和 iOS 固有的 2 帧延迟。
-
大约半秒。 Waaaaay 非常适合任何良好的用户体验。我想知道,我应该学习 SprikeKit 并使用 overlaySKScene 属性而不是向 overlaySKScene 添加按钮吗?