- (void) startLoading {
[self blink];
}
- (void) blink {
[UIView animateWithDuration:0.5
delay: 0.0
options: UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseOut
animations:^{
//animate stuff
}
completion:^(BOOL finished){
[self blink];
}];
}
- (void) stopLoading {
//What goes here?
}
在我UIView的initWithFrame
,我建立了一些裝載圖形然後從[self startLoading]
啓動加載程序動畫。取消塊的UIView animateWithDuration
現在的問題是,我該如何阻止這種'無限循環'?或stopLoading或dealloc方法能夠很好地分離所有東西嗎?
當我忽視的事實是一個完成塊是存在的,只是從超視圖釋放我UIView,一切順利幾秒鐘(比規定的0.5秒以上),則應用程序崩潰與消息:
malloc: * mmap(size=2097152) failed (error code=12) error: can't allocate region ** set a breakpoint in malloc_error_break to debug
我在malloc_error_break中有一個斷點,罪魁禍首就是動畫塊。
我假設UIView是通過從超級視圖中刪除而釋放的,稍後在完成塊被執行時,參考self
這是消息發佈的對象。
我在文檔中找不到任何關於取消「排隊」塊的內容。
再次感謝馬特。我慢慢的開始關注動畫塊的事情 - 尤其是它不是'免費'的內存/ CPU。 – RickiG
這種方法有一個不便之處。如果在飛行動畫塊完成之前將NO設置爲標記kCancel,則會再次調用閃爍方法。小心它。我希望有一種方法可以像cancelPreviousPerformRequestsWithTarget一樣永久取消塊,但顯然沒有辦法。 – erkanyildiz
小點,但'kVariable'命名約定應該只能用於真正的靜態值 - 例如,類中按鈕的標準寬度等。這些通常實際上是用'const'參數聲明的。 - 相反,只需使用描述性變量名稱即可。 – toblerpwn