2012-03-01 35 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

你爲什麼不動畫上線畫出 – 2012-03-01 05:20:48

+0

什麼ü意思有何看法?我正在放圖。所以當圖形出現時,線條應該從起點移動到終點 – Shreedhar 2012-03-01 05:23:05

回答

1

我相信你需要採取不同的方法。 我會告訴你一個水平線的例子,垂直的情況將非常相似。 使用一個正常的UIView與象最初的框架來代表您行:

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!"); 
      }];