2011-12-28 54 views
0

我正在使用下面的函數在兩個座標之間繪製一條線現在我想要顯示像線那樣的旋轉動畫是逐點繪製的,所以我該怎麼做?動畫同時畫線

  x1 = [[xCoordinates objectAtIndex:i]intValue]; 
      y1 = [[yCoordinates objectAtIndex:i]intValue]; 

      x2 = [[xCoordinates objectAtIndex:i+1]intValue]; 
      y2 = [[yCoordinates objectAtIndex:i+1]intValue]; 
      UIImageView *drawImage = [[UIImageView alloc] init]; 
      drawImage.frame = self.view.frame; 
      [self.view addSubview:drawImage]; 

      UIGraphicsBeginImageContext(self.view.frame.size); 
      [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
      CGContextRef context = UIGraphicsGetCurrentContext(); 
      CGContextSetLineCap(context, kCGLineCapRound); 
      CGContextSetLineWidth(context, 5.0); 
      CGContextSetRGBStrokeColor(context, 0.5, 1.0, 1.0, 1.0); 
      CGContextMoveToPoint(context, xBegin, yBegin); 
      CGContextAddLineToPoint(context, x1, y1); 
      CGContextStrokePath(context); 
      drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
      UIGraphicsEndImageContext(); 
      [drawImage release]; 
      [UIView commitAnimations]; 

回答

0

這裏是一個示例代碼,可能會幫助你實現你想要的東西http://nachbaur.com/blog/core-animation-part-4

+0

這是一個很好的代碼,但對我沒有幫助bcz我想要在兩點之間繪製線條時將動畫作爲逐個像素的動畫 –

+0

有很多算法可以獲得位於起點和終點之間的點。我以爲你知道這件事。這就是爲什麼我只提供動畫代碼。 – Iducool