所以我有兩個問題,但都是相關的。NSTimer問題
我創建了一個「動畫」,當使用
NSTimer
單擊按鈕時,會移動進度視圖。這個動畫在點擊按鈕的前幾個時間點工作正常,但在此之後,它開始加速該過程,實際上從NSTimer
循環的最初開始跳到NSTimer
循環的末尾。我想知道是否有人聽說過這個問題和/或知道解決方案?我創造了同樣的事情在問題1,但在
UItableViewCell
並按下編輯按鈕時NSTimer
循環被激活。編輯按鈕激活具有此[self.tableView2 setEditing:NO animated:YES];
和NSTimer
scheduledTimerWithInterval
...(進度視圖動畫)的功能。這裏的問題是,setEdit動畫不再只是彈出它的動畫。再一次,有沒有人知道這個解決方案?
這裏是問題2的代碼(無論是對問題的代碼是非常相似的,所以如果你能發現這裏的問題,那麼很可能我可以使用該解決方案來解決這些問題都):
-(void)editTable{
[self.tableView2 setEditing:YES animated:YES];
iCount = 8;
iCount2 = 257;
forwardProgress = YES;
animationFlag = YES;
myTimer = [NSTimer scheduledTimerWithTimeInterval:0.001f target:self selector:@selector(increaseAmount) userInfo:nil repeats:YES];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(cancelEdit)];
}
-(void)cancelEdit{
[self.tableView2 setEditing:NO animated:YES];
forwardProgress = NO;
animationFlag = YES;
iCount = 38;
iCount2 = 227;
myTimer = [NSTimer scheduledTimerWithTimeInterval:0.001f target:self selector:@selector(increaseAmount) userInfo:nil repeats:YES];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editTable)];
}
-(void)increaseAmount{
float max = 38.0f;
float max2 = 257.0f;
float min2 = 227.0f;
float min = 8.0f;
if (animationFlag == YES) {
if (forwardProgress == YES) {
if (iCount <= max) {
iCount++;
// NSLog(@"iCount = %i", iCount);
}
if (iCount2 >= min2) {
iCount2--;
// NSLog(@"iCount2 = %i", iCount2);
}
if (iCount <= max) {
[tableView2 reloadData];
}
if (iCount2 >= min2) {
[tableView2 reloadData];
}
if (iCount == max) {
animationFlag = NO;
}
newFrame = CGRectMake(iCount, 33.0f, iCount2, 11.0f);
[tableView2 reloadData];
}else{
if (iCount >= min) {
iCount--;
NSLog(@"iCount = %i", iCount);
}
if (iCount2 <= max2) {
iCount2++;
NSLog(@"iCount2 = %i", iCount2);
}
newFrame = CGRectMake(iCount, 33.0f, iCount2, 11.0f);
if (iCount >= min) {
[tableView2 reloadData];
}
if (iCount2 <= max2) {
[tableView2 reloadData];
}
if (iCount == min) {
animationFlag = NO;
}
}
}
}
通過一切手段,郵政編碼。隔離展現這些行爲並共享的最小塊。 1.聽起來有點像你後續的點擊是創造更多的定時器來移動按鈕,而不取消以前的;或者定時器正在使用某些狀態,這些狀態在點擊之間沒有得到重置(例如,如果您有一個加速因子可以輕鬆進入,並且不會重置它。) 2.不太確定...你是否在調用任何用於管理動畫事務的UIView類方法? – rgeorge