我从来没有做过之前的任何编码,直到几个星期前进行的行动,并同时我对我自己做出合理的进展,我与挣扎的东西,我希望有人不会介意帮助。如何在简单的UIView动画
我试图做一个简单的应用程序为我女儿斯威夫特(的Xcode 7.3版 - 7D175)。这是一系列动画,角色在月球陨石坑内上下跳动。
我希望能够做的,是调用一个函数时按下动画UIImages之一。理想情况下,我想它来播放声音按下动画的时候(我知道该怎么称呼的声音,只是没有以这种方式)
我创建了一个类,我写的代码为动画
func alienAnimate() {
UIView.animateWithDuration(0.3, delay: 0, options: [.CurveLinear, .AllowUserInteraction], animations: {
self.center.y -= 135
}, completion: nil)
UIView.animateWithDuration(0.3, delay: 3, options: [.CurveLinear, .AllowUserInteraction], animations: {
self.center.y += 135
}, completion: nil)
}
如果有人能在正确的方向指向我,我会非常感谢。我猜可能有更好的动画方式,但这是我现在知道的。
编辑 - 5月2日
行,所以我最终得到了它的工作...好,几乎:)它仍然无法正常工作正是我想,但我的工作就可以了。
的动画基本上沿(所以外星人弹出像他们出来一个洞)的路径垂直移动。下面的代码可以工作,但仍然允许您在它的路径开始处点击图像,当它实际上位于一个洞的下方时。
我还需要解决如何单击它实际上是现在,而不能按它的出发点。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first
let touchLocation = touch!.locationInView(self.view)
if self.imgAlien.layer.presentationLayer()!.hitTest(touchLocation) != nil {
sfxPop.play()
} else if self.imgAlien.layer.presentationLayer()!.hitTest(touchLocation) != nil {
sfxPop.play()
} else if self.imgAlien2.layer.presentationLayer()!.hitTest(touchLocation) != nil {
sfxPop.play()
} else if self.imgAlien3.layer.presentationLayer()!.hitTest(touchLocation) != nil {
sfxPop.play()
} else if self.imgAlien4.layer.presentationLayer()!.hitTest(touchLocation) != nil {
sfxPop.play()
} else if self.imgAlien5.layer.presentationLayer()!.hitTest(touchLocation) != nil {
sfxPop.play()
} else if self.imgUFO.layer.presentationLayer()!.hitTest(touchLocation) != nil {
sfxPop.play()
}
}
道歉,如果这是没有足够的信息,开心张贴更多,如果需要,我只是不想太多的信息,如果它不需要:) –
我没有看到任何代码相关的图像在这里..只是移动的子类。如果它确实是外星人类,让我们知道,以便我们可以回答它 – Shubhank
这听起来像你想要做的事情出来的盒子与Sprite套件。你可能想看看一个Sprite套件教程,看看它是否值得改变你的实现 – bolnad