2012-03-01 17 views
1

グラフに縦線を描くコードです。開始点から終了点までラインをアニメーション化する方法

-(void)drawRect:(CGRect)rect 
    {  

      AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate; 

    UIBezierPath *breakFastValuePath = [UIBezierPath bezierPath]; 

    [breakFastValuePath moveToPoint:CGPointMake(89, 288)]; 
     [breakFastValuePath addLineToPoint:CGPointMake(89,288-delegate.breakFastTotalamt)]; 
     [breakFastValuePath closePath]; 
     [[UIColor greenColor] setStroke]; 
     breakFastValuePath.lineWidth = 10; 
     [breakFastValuePath stroke]; 
    } 

開始点から終了点までの線アニメーションを作成するにはどうすればいいですか?

+0

なぜあなたは –

+0

uは何を意味描かれたライン上のビューをアニメーション化していない: は次のように初期フレームを使用して行を表すために、通常のUIViewを使用しますか?私はグラフを入れています。だから、グラフが始点から終点まで動くはずです – Shreedhar

答えて

1

私はあなたが別のアプローチを取る必要があると信じています。 私はあなたに水平線の例を示します、垂直の場合は非常に似ています。

UIView *lineView = [[UIView alloc] initWithFrame: 
        CGRectMake(startX,startY,1,lineThickness)];//Line starts as 1 pixel long. 
//Then you need to animate this inside loadView: 
[UIView animateWithDuration:1//Amount of time the animation takes. 
        delay:0//Amount of time after which animation starts. 
       options: UIViewAnimationCurveEaseOut//How the animation will behave. 
      animations:^{ 
       //here you can either set a CGAffineTransform, or change your view's frame. 
       //Both will work just fine. 
       lineView = CGAffineTransformMakeScale (
       scaleForX,//say 100, Now the line will be a 100 pixels long. 
       scaleForY//say 1, Maintain line thickness.  
       //direction. 
       //Note* you could also set the frame for a similar effect. 
       //view's frame. 
       //lineView.frame = CGRectMake(startX,startY,finalLength,lineThickness) 
      } 
      completion:^(BOOL finished){//This block is called when the animation completes. 
       NSLog(@"Done!"); 
      }]; 
関連する問題