绘制线条时的动画

时间:2011-12-28 10:36:06

标签: iphone ios

我正在使用下面的函数在两个坐标之间绘制一条线现在我想要显示像线一样的旋转动画逐一绘制,所以我该怎么做?

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

1 个答案:

答案 0 :(得分:0)

以下示例代码可帮助您实现所需内容http://nachbaur.com/blog/core-animation-part-4