1
我試圖根據陣列[0,1,1,0,0,1,1,0]
(黑色 - 白色其1)或(白色 - 黑色0)中的位閃爍iPhone屏幕(UIView的背景顏色)。根據陣列中的位閃爍/閃爍UIView
但我無法弄清楚如何在動畫中使用循環和條件。
不工作密碼
Byte u = 65;
self.myBlock.backgroundColor = [UIColor blackColor];
int i = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationRepeatCount:8.0];
[UIView setAnimationRepeatAutoreverses:NO];
if (((u >> i) & 1) == 1) {
self.myBlock.backgroundColor = [UIColor blackColor];
self.myBlock.backgroundColor = [UIColor whiteColor];
printf("1");
} else {
self.myBlock.backgroundColor = [UIColor whiteColor];
self.myBlock.backgroundColor = [UIColor blackColor];
printf("0");
}
i++; // how it can be increased ?
[UIView commitAnimations];
有什麼建議?
嗨德米特里,並歡迎堆棧溢出。你能否擴展你的問題,描述當你嘗試你認爲不工作的代碼時出了什麼問題? –
只學習如何在動畫中使用循環和條件。在我的代碼var我沒有增加。編譯器做所有的計算和在UIview中我只看到它的最終結果。 我認爲這個塊 [UIView beginAnimations:nil context:nil]; [UIView commitAnimations]; 像循環一樣工作。 – Dmitry