Как оживить линию от начальной точки до конечной точки - PullRequest
1 голос
/ 01 марта 2012

Вот код, который рисует вертикальную линию на графике.

-(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];
    }

Как сделать так, чтобы анимация линии от начальной точки до конечной точки загружалась?

Ответы [ 2 ]

1 голос
/ 19 июня 2013

Я считаю, что вам нужно придерживаться другого подхода.Я покажу вам пример для горизонтальной линии, вертикальный случай будет очень похожим.Используйте обычный 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!");
             }]; 
1 голос
/ 01 марта 2012

Вы можете анимировать strokeEnd от 0,0 до 1,0, чтобы получить эффект, что линия вдоль ее пути от начала до конца. Посмотрите на этот вопрос (о рисовании круга в Core Animation) для справки.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...