[英]animations ios objective-c
我有一個全局變量p。 我有一個函數可以根據此全局變量的值繪制(或重新繪制)我的復雜UIView對象。 當我增加p時,我的uiview對象需要重繪。 我需要使用動畫來完成。
double pInitialValue=0.5;
double pNewValue=1.0;
//somewhere before animation we must call [self redraw] to draw our view with p=pInitialValue;
//then, when we call animate function.
//we change p to pNewValue
//and every step must be redrawed using [self redraw]
p=pNewValue; //using animation p must slowly grow from pInitialValue to pNewValue
[self redraw]; //and ofcourse user must see every step of animation so we need to call redraw function
例如,我需要一個持續時間為4的動畫。這意味着在這4秒鍾內,我的p必須從pInitialValue增長到pNewValue,並且在每一步中我的重繪函數都必須被調用
請幫幫我。 如何做呢?
您可以使用計時器來增加p
值。 這樣做:在類中定義一個實例變量,如下所示:
NSTimer *timer;
之后,在您希望動畫發生之前,請執行以下操作:
CGFloat timerInterval = 1 / 30; // This means 30 frames per second. Change this as you want.
timer = [NSTimer scheduledTimerWithTimeInterval:timerInterval target:self selector:@selector(increaseP) userInfo:nil repeats:YES];
不是有一個名為方法increaseP
是這樣的:
- (void)increaseP
{
if (p < maxPValue) {
// Increase p here and redraw your things
}
else {
[timer invalidate];
}
}
讓我知道您是否有任何疑問,是否適合您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.