任何人都可以請幫我解決這個問題嗎?我有nsarray線,我需要在一些UIView中一個接一個地寫下它們(我想爲手繪圖製作動畫)。在UIView中動畫繪製線條
3
A
回答
-1
您可能最終實現了視圖drawRect方法。 這http://howtomakeiphoneapps.com/2009/08/how-to-draw-shapes-with-core-graphics/
應該讓你開始
0
一些入口點,可以幫助:
0
這個代碼動畫一個集合上的對象點。可以使用相同的想法爲您的線路,我假設是CGPath?
//
// animate along a set of points
//
// NSLog(@"The content of movement1PointsArray is%@",movement1PointsArray);
CGMutablePathRef touchPath1 = CGPathCreateMutable();
CGPoint touchPath1StartPoint = [[movement1PointsArray objectAtIndex:0] CGPointValue];
CGPathMoveToPoint(touchPath1,NULL,touchPath1StartPoint.x, touchPath1StartPoint.y);
for (NSInteger p = 0; p < [movement1PointsArray count]; ++p)
{
CGPoint touchesPointOnPath = [[movement1PointsArray objectAtIndex:p] CGPointValue];
CGPathAddLineToPoint(touchPath1, NULL,touchesPointOnPath.x,touchesPointOnPath.y);
}
CAKeyframeAnimation* touchPathAnimation1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
[touchPathAnimation1 setDuration: 1.0];
[touchPathAnimation1 setAutoreverses: NO];
touchPathAnimation1.removedOnCompletion = NO;
touchPathAnimation1.fillMode = kCAFillModeForwards;
[touchPathAnimation1 setPath: touchPath1];
CFRelease(touchPath1);
[animationsArray addObject:touchPathAnimation1];
[ball.layer addAnimation: touchPathAnimation1 forKey: @"position"];
-
我有麻煩的第二路徑動畫...
- 不管我怎麼努力,它只是動畫的最後一條路徑。
5
下面是答案(這裏找到:http://soulwithmobiletechnology.blogspot.fr/2012/07/how-to-animate-line-draw.html)
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(50.0,0.0)];
[path addLineToPoint:CGPointMake(120.0, 600.0)];
CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.view.bounds;
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [[UIColor redColor] CGColor];
pathLayer.fillColor = nil;
pathLayer.lineWidth = 2.0f;
pathLayer.lineJoin = kCALineJoinBevel;
[self.view.layer addSublayer:pathLayer];
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 2.0;
pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
[pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
不要忘記#import <QuartzCore/QuartzCore.h>
。
相關問題
- 1. 在基於動畫CGPoint的UIView中繪製一條線。
- 2. 在Three.js中爲線條繪製動畫
- 3. 動畫CGContext中繪製的線條
- 4. 在畫布中繪製動畫曲線
- 5. 動畫繪製一條線(石英2D?)
- 6. 繪製動畫線
- 7. 用畫布繪製線條
- 8. 使用請求動畫框在畫布中動畫繪製線條
- 9. 如何使用JavaScript爲動畫元素繪製線條動畫
- 10. 如何在Silverlight中繪製動畫線?
- 11. 在Pixi.js中爲一條線繪製動畫效果
- 12. 在Google地球插件中繪製動畫線條
- 13. 如何在Objective C中繪製線條的動畫?
- 14. 如何在iPhone開發中動畫線條繪製?
- 15. 上的UIView繪製圖形動畫
- 16. 安卓繪製動畫線
- 17. 在OpenGL中繪製線條
- 18. 檢測在UIView中繪製的線條上的點擊
- 19. 在UIView子視圖中繪製一條線
- 20. 用動畫重繪UIView
- 21. HTML畫布繪製清晰的線條
- 22. 用畫布繪製流暢的線條
- 23. 動畫的線,而在WPF繪製
- 24. 僅在圖像邊框上使用Android繪製線條動畫
- 25. 在IOS上使用Quartz 2d編程動畫繪製一條線
- 26. 安卓繪製動畫虛線曲線
- 27. 在動態創建的UIView中畫線
- 28. 定製UIView動畫中disModalViewController
- 29. 繪畫區域動態線條圖
- 30. 繪製在畫布光線
線條如何存儲在NSArray中? – Kalle 2011-04-03 08:00:00