欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

flutter RotationTransition實(shí)現(xiàn)旋轉(zhuǎn)動(dòng)畫

 更新時(shí)間:2019年07月17日 11:33:25   作者:早起的年輕人  
這篇文章主要為大家詳細(xì)介紹了flutter RotationTransition實(shí)現(xiàn)旋轉(zhuǎn)動(dòng)畫,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了flutter RotationTransition實(shí)現(xiàn)旋轉(zhuǎn)動(dòng)畫的具體代碼,供大家參考,具體內(nèi)容如下

flutter 動(dòng)畫狀態(tài)監(jiān)聽(tīng)器

AnimationController

 //動(dòng)畫控制器
  AnimationController controller;
 //AnimationController是一個(gè)特殊的Animation對(duì)象,在屏幕刷新的每一幀,就會(huì)生成一個(gè)新的值,
 // 默認(rèn)情況下,AnimationController在給定的時(shí)間段內(nèi)會(huì)線性的生成從0.0到1.0的數(shù)字
 //用來(lái)控制動(dòng)畫的開(kāi)始與結(jié)束以及設(shè)置動(dòng)畫的監(jiān)聽(tīng)
 //vsync參數(shù),存在vsync時(shí)會(huì)防止屏幕外動(dòng)畫(動(dòng)畫的UI不在當(dāng)前屏幕時(shí))消耗不必要的資源
 //duration 動(dòng)畫的時(shí)長(zhǎng),這里設(shè)置的 seconds: 2 為2秒,當(dāng)然也可以設(shè)置毫秒 milliseconds:2000.
 controller =
  AnimationController(duration: const Duration(seconds: 2), vsync: this);
 //動(dòng)畫開(kāi)始、結(jié)束、向前移動(dòng)或向后移動(dòng)時(shí)會(huì)調(diào)用StatusListener
 controller.addStatusListener((status) {
  if (status == AnimationStatus.completed) {
  //動(dòng)畫從 controller.reverse() 反向執(zhí)行 結(jié)束時(shí)會(huì)回調(diào)此方法
  print("status is completed");
  // controller.reset(); 將動(dòng)畫重置到開(kāi)始前的狀態(tài)
  //開(kāi)始執(zhí)行
  //controller.forward();
  } else if (status == AnimationStatus.dismissed) {
  //動(dòng)畫從 controller.forward() 正向執(zhí)行 結(jié)束時(shí)會(huì)回調(diào)此方法
  print("status is dismissed");
  //controller.forward();
  }else if (status == AnimationStatus.forward) {
  print("status is forward");
  //執(zhí)行 controller.forward() 會(huì)回調(diào)此狀態(tài)
  }else if (status == AnimationStatus.reverse) {
  //執(zhí)行 controller.reverse() 會(huì)回調(diào)此狀態(tài)
  print("status is reverse");
  }
 });

AnimationController 的常用操作說(shuō)明

flutter AnimationStatus 動(dòng)畫狀態(tài)說(shuō)明

1 flutter RotationTransition實(shí)現(xiàn)旋轉(zhuǎn)動(dòng)畫

 //動(dòng)畫控制器
 AnimationController controller;


 //AnimationController是一個(gè)特殊的Animation對(duì)象,在屏幕刷新的每一幀,就會(huì)生成一個(gè)新的值,
 // 默認(rèn)情況下,AnimationController在給定的時(shí)間段內(nèi)會(huì)線性的生成從0.0到1.0的數(shù)字
 //用來(lái)控制動(dòng)畫的開(kāi)始與結(jié)束以及設(shè)置動(dòng)畫的監(jiān)聽(tīng)
 //vsync參數(shù),存在vsync時(shí)會(huì)防止屏幕外動(dòng)畫(動(dòng)畫的UI不在當(dāng)前屏幕時(shí))消耗不必要的資源
 //duration 動(dòng)畫的時(shí)長(zhǎng),這里設(shè)置的 seconds: 2 為2秒,當(dāng)然也可以設(shè)置毫秒 milliseconds:2000.
 controller =
  AnimationController(duration: const Duration(seconds: 2), vsync: this);
 //動(dòng)畫開(kāi)始、結(jié)束、向前移動(dòng)或向后移動(dòng)時(shí)會(huì)調(diào)用StatusListener
 controller.addStatusListener((status) {
  if (status == AnimationStatus.completed) {
  //動(dòng)畫從 controller.forward() 正向執(zhí)行 結(jié)束時(shí)會(huì)回調(diào)此方法
  print("status is completed");
  } else if (status == AnimationStatus.dismissed) {
  //動(dòng)畫從 controller.reverse() 反向執(zhí)行 結(jié)束時(shí)會(huì)回調(diào)此方法
  print("status is dismissed");
  } else if (status == AnimationStatus.forward) {
  print("status is forward");
  //執(zhí)行 controller.forward() 會(huì)回調(diào)此狀態(tài)
  } else if (status == AnimationStatus.reverse) {
  //執(zhí)行 controller.reverse() 會(huì)回調(diào)此狀態(tài)
  print("status is reverse");
  }
 });

執(zhí)行動(dòng)畫的 widget

 //旋轉(zhuǎn)
 Widget buildRotationTransition() {
 return Center(
  child: RotationTransition(
  //設(shè)置動(dòng)畫的旋轉(zhuǎn)中心
  alignment: Alignment.center,
  //動(dòng)畫控制器
  turns: controller,
  //將要執(zhí)行動(dòng)畫的子view
  child: Container(
   width: 100,
   height: 100,
   color: Colors.grey,
  ),
  ),
 );
 }
}

2 flutter RotationTransition實(shí)現(xiàn)無(wú)限循環(huán)旋轉(zhuǎn)動(dòng)畫

實(shí)現(xiàn)方法 就是在動(dòng)畫結(jié)束的時(shí)候再開(kāi)啟動(dòng)畫

//動(dòng)畫開(kāi)始、結(jié)束、向前移動(dòng)或向后移動(dòng)時(shí)會(huì)調(diào)用StatusListener
 controller.addStatusListener((status) {
  if (status == AnimationStatus.completed) {
  //動(dòng)畫從 controller.forward() 正向執(zhí)行 結(jié)束時(shí)會(huì)回調(diào)此方法
  print("status is completed");
  //重置起點(diǎn)
  controller.reset();
  //開(kāi)啟
  controller.forward();
  } else if (status == AnimationStatus.dismissed) {
  //動(dòng)畫從 controller.reverse() 反向執(zhí)行 結(jié)束時(shí)會(huì)回調(diào)此方法
  print("status is dismissed");
  } else if (status == AnimationStatus.forward) {
  print("status is forward");
  //執(zhí)行 controller.forward() 會(huì)回調(diào)此狀態(tài)
  } else if (status == AnimationStatus.reverse) {
  //執(zhí)行 controller.reverse() 會(huì)回調(diào)此狀態(tài)
  print("status is reverse");
  }
 });

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論