1
每次的NSTimer被稱爲我的動畫被取消的NSTimer取消我UIView.animateWithDuration
override func viewDidLoad() {
super.viewDidLoad()
_ = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "timer:", userInfo: nil, repeats: true)
self.mover()
}
/**
Selector
- parameter timer: NStimer
*/
func timer(timer:NSTimer!){
self.lblTiempo.text = "Te haz movido"
}
如何防止的NSTimer取消我的動畫?
/**
Mueve la imagen en la pantalla
*/
func mover(){
let x = Int(arc4random_uniform(UInt32(400)))
let y = Int(arc4random_uniform(UInt32(400)))
UIView.animateWithDuration(self.juego!.velocidad,
delay: 0.0,
options: [.CurveEaseInOut, .AllowUserInteraction],
animations: {
self.imgBicho.center = CGPoint(x: x, y: y)
},
completion: { finished in
self.mover()
})
}
我對IOS的開發比較陌生,有人可以幫助我,謝謝。
當然paulvs,對不起,它是一個拼寫錯誤。問題是用的NSTimer :(
Sure paulvs,對不起,它是一個拼寫錯誤。 NSTimer的問題是: – Izak
我把你的代碼複製到一個空的項目中,分別將'UILabel'和'UIImageView'連接到'lblTiempo'和'imgBicho',然後我將'self.juego!.velocidad'用'1'運行該項目並在屏幕上跳舞出一個圖像,那麼究竟是什麼問題?圖像是否完全移動? – paulvs
當用定時器更新視圖時,圖像消失並出現另一方面,我的動畫沒有結束,請原諒我的英語,我不會說或寫得很好,如果我刪除了定時器,圖像會流暢地流動,不會消失 – Izak