簡(jiǎn)介
注意事項(xiàng)
values(NSArray *)
path(CGPathRef)
keyTimes(NSArray
timingFunctions(NSArray
calculationMode(NSString *)
rotationMode(NSString *)
效果圖

實(shí)現(xiàn)思路
實(shí)現(xiàn)步驟(自定義UIView的子類)
@property (nonatomic, strong) UIBezierPath *path;監(jiān)聽(tīng)觸摸事件的狀態(tài),繪制貝瑟爾曲線
//確定起點(diǎn)- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //獲取當(dāng)前觸摸點(diǎn) UITouch *touch = [touches anyObject]; CGPoint curretnPoint = [touch locationInView:self]; //創(chuàng)建路徑 UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:curretnPoint]; //保存路徑 self.path = path;}//添加線條- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ //獲取當(dāng)前觸摸點(diǎn) UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self]; //添加線條 [self.path addLineToPoint:currentPoint]; //重繪,將曲線顯示到圖層上 [self setNeedsDisplay];}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ //創(chuàng)建動(dòng)畫(huà) CAKeyframeAnimation *animation = [CAKeyframeAnimation animation]; //指定執(zhí)行動(dòng)畫(huà)的屬性, animation.keyPath = @"position"; //設(shè)置動(dòng)畫(huà)的執(zhí)行路徑 animation.path = self.path.CGPath; //設(shè)置動(dòng)畫(huà)的執(zhí)行時(shí)間 animation.duration = 1; //設(shè)置動(dòng)畫(huà)的重復(fù)次數(shù) animation.repeatCount = MAXFLOAT; //將動(dòng)畫(huà)添加到對(duì)應(yīng)的圖層上 [[[self.subviews firstObject] layer] addAnimation:animation forKey:nil];}將路徑顯示到圖層上
//繪制路徑- (void)drawRect:(CGRect)rect{ [self.path stroke];}新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注