[英]How to create and delay an animation in objective-c?
我有一個5x5的跳棋板自定義UIView
,它填充了我單擊為黑色的框。 我想創建一個動畫,程序在程序中會按順序記住我的點擊,然后按一下按鈕,它會按照我執行的順序進行動畫處理並將框填充為黑色。 如何在每次過渡之間有2秒的間隔創建這種動畫?
謝謝你的幫助。
您可以使用NSTimer等待2秒,然后瀏覽您定義的動畫數組。
因此,首先您需要存儲您的點擊順序
NSMutableArray * clicks = [[NSMutableArray alloc] init];
在您的“ .h”中聲明一個int計數器: int cont
,並將其設置為0。
然后,當您想開始制作動畫時,請初始化NSTimer:
NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fillAnotherSquare:) userInfo:nil repeats:YES];
最后,您的方法“ fillAnotherSquare”
-(void) fillAnotherSquare: (id ) sender{
if (cont == squareNumbers)
[timer invalidate];
/* Fill the square with index "cont" */
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.