国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

CoreAnimation-06-CAKeyframeAnimation

2019-11-14 18:25:29
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

概述


  • 簡(jiǎn)介

    • CAKeyframeAnimation又稱關(guān)鍵幀動(dòng)畫(huà)
    • CAKeyframeAnimation是抽象類CAPRopertyAnimation的子類,可以直接使用
    • 通過(guò)values與path兩個(gè)屬性指定動(dòng)畫(huà)屬性
  • 注意事項(xiàng)

    • 若指定了path屬性,則values屬性將被忽略
    • CABasicAnimation相當(dāng)于只有兩個(gè)關(guān)鍵幀的CAKeyframeAnimation

關(guān)鍵幀動(dòng)畫(huà)的常用屬性


  • values(NSArray *)

    • 存放關(guān)鍵幀的多個(gè)值
    • 類似于CABasicAnimation的fromValue與toValue值
  • path(CGPathRef)

    • 動(dòng)畫(huà)的執(zhí)行路徑
    • 可以通過(guò)繪圖的方式繪制路徑
  • keyTimes(NSArray *)

    • 每個(gè)關(guān)鍵幀的執(zhí)行時(shí)間
    • 類型為NSNumber類型
    • 若不指定,則所有的關(guān)鍵幀平分動(dòng)畫(huà)的duration時(shí)長(zhǎng)
  • timingFunctions(NSArray *)

    • 速度控制函數(shù)數(shù)組
  • calculationMode(NSString *)

    • 指定關(guān)鍵幀的動(dòng)畫(huà)屬性
    • 若指定該值,則keyTimes與timingFunctions屬性值將被忽略
    • 默認(rèn)為:kCAAnimationLinear
  • rotationMode(NSString *)

    • 指定旋轉(zhuǎn)模式,默認(rèn)為nil

示例


  • 效果圖

  • 實(shí)現(xiàn)思路

    • 通過(guò)監(jiān)聽(tīng)執(zhí)行動(dòng)畫(huà)的UI控件的觸摸事件來(lái)繪制貝瑟爾曲線
    • 創(chuàng)建關(guān)鍵幀動(dòng)畫(huà),指定執(zhí)行動(dòng)畫(huà)的keyPath屬性
    • 將繪制的貝瑟爾曲線作為動(dòng)畫(huà)的執(zhí)行路徑
    • 將動(dòng)畫(huà)添加到指定的圖層上
  • 實(shí)現(xiàn)步驟(自定義UIView的子類)

    • 使用成員屬性保存貝瑟爾路徑
    @property (nonatomic, strong) UIBezierPath *path;
    • 監(jiān)聽(tīng)觸摸事件的狀態(tài),繪制貝瑟爾曲線

      • 開(kā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;}
      • 移動(dòng)
      //添加線條- (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];}
      • 結(jié)束(創(chuàng)建動(dòng)畫(huà))
      - (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];}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 梁河县| 西盟| 海口市| 龙岩市| 丹棱县| 丰宁| 皋兰县| 遂平县| 廉江市| 深圳市| 兴和县| 济南市| 昭平县| 正镶白旗| 江口县| 都安| 容城县| 木兰县| 望城县| 恩施市| 蓬安县| 福鼎市| 綦江县| 边坝县| 沅江市| 甘泉县| 湖州市| 乌拉特中旗| 南安市| 昂仁县| 苍南县| 蓝山县| 衡阳市| 璧山县| 林州市| 莲花县| 简阳市| 双鸭山市| 凉城县| 祁门县| 游戏|