我從來沒有做過之前的任何編碼,直到幾個星期前進行的行動,並同時我對我自己做出合理的進展,我與掙扎的東西,我希望有人不會介意幫助。如何在簡單的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