2014-10-21 21 views
0

當在我的應用程序中單擊圖像並且圖像位於頂部時,圖像將始終向下移動。但是當圖像處於底部時,圖像不會向上移動。即使它不移動,該進程仍在運行,並且它會記錄在頂部。我嘗試了一切,我知道該怎麼做,但你看到有什麼不對嗎?謝謝!!CGRectMake不移動圖像(有時)

- (void)imageTapped:(UITapGestureRecognizer *) gestureRecognizer 
{ 
    NSLog(@"imageTapped"); 

    [UIView beginAnimations:@"move" context:nil]; 
    [UIView setAnimationDuration:0.3]; 

    if (self.imgV.frame.origin.y == 20) { 

     NSLog(@"Top"); 

     upOrDown = @"1"; 


     self.invalidateTheTimer = @""; 
     timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES]; 

     self.imgV.frame=CGRectMake(0, self.view.frame.size.height-self.imgV.frame.size.height, self.imgV.frame.size.width, self.imgV.frame.size.height); 
     self.vBottom.frame=CGRectMake(0, self.imgV.frame.origin.y+self.imgV.frame.size.height, self.vBottom.frame.size.width, self.vBottom.frame.size.height); 

    } else if (self.imgV.frame.origin.y >= 507) { 

     NSLog(@"Bottom"); 


     self.imgV.frame=CGRectMake(0, 20, self.imgV.frame.size.width, self.imgV.frame.size.height); 
     self.vBottom.frame=CGRectMake(0, self.imgV.frame.origin.y+self.imgV.frame.size.height, self.vBottom.frame.size.width, self.vBottom.frame.size.height); 



     [hour setText:@""]; 
     [minute setText:@""]; 
     [second setText:@""]; 

     [timer invalidate]; 
     self.invalidateTheTimer = @"INVALIDATE"; 



    } 

     NSLog(@"%f", self.imgV.frame.origin.y); 
    [UIView commitAnimations]; 

} 

回答

0

考慮你有沒有張貼整個代碼,這是很難搞清楚什麼是錯的,可是看着你搞得一團糟,我建議你看看到block based animations應該簡化你」重新努力完成。

此外,如果我不得不猜測,我會說這個問題是在你的計時器和它調用的任何方法可能與你的動畫搞亂。