最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Flutter 實現(xiàn)酷炫的3D效果示例代碼

 更新時間:2020年07月23日 08:56:46   作者:老孟Flutter  
這篇文章主要介紹了Flutter 實現(xiàn)酷炫的3D效果,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

此文講解3個酷炫的3D動畫效果。

下面是要實現(xiàn)的效果:

Flutter 中3D效果是通過 Transform 組件實現(xiàn)的,沒有變換效果的實現(xiàn):

class TransformDemo extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 return Scaffold(
 appBar: AppBar(
 title: Text('3D 變換Demo'),
 ),
 body: Container(
 alignment: Alignment.center,
 color: Colors.white,
 child: Text('3D 變換Demo'),
 ),
 );
 }
}

通過 GestureDetector 組件添加滑動事件監(jiān)聽:

@override
Widget build(BuildContext context) {
 return Scaffold(
 appBar: AppBar(
 title: Text('3D 變換Demo'),
 ),
 body: GestureDetector(
 onPanUpdate: (details) {
 print('$details');
 },
 child: Container(
 alignment: Alignment.center,
 color: Colors.white,
 child: Text('3D 變換Demo'),
 ),
 ),
 );
}

添加 Transform 對組件進(jìn)入旋轉(zhuǎn):

@override
Widget build(BuildContext context) {
 return Transform(
 transform: Matrix4.identity()
 ..setEntry(3, 2, 0.001)
 ..rotateX(pi/6)
 ..rotateY(pi/6),
 alignment: Alignment.center,
 child: Scaffold(
 appBar: AppBar(
  title: Text('3D 變換Demo'),
 ),
 body: GestureDetector(
  onPanUpdate: (details) {
  },
  child: Container(
  alignment: Alignment.center,
  color: Colors.white,
  child: Text('3D 變換Demo'),
  ),
 ),
 ));
}

將滑動的偏移和旋轉(zhuǎn)進(jìn)行關(guān)聯(lián):

class TransformDemo extends StatefulWidget {
 @override
 _TransformDemoState createState() => _TransformDemoState();
}

class _TransformDemoState extends State<TransformDemo> {
 double _rotateX = .0;
 double _rotateY = .0;

 @override
 Widget build(BuildContext context) {
 return Transform(
 transform: Matrix4.identity()
  ..rotateX(_rotateX)
  ..rotateY(_rotateY),
 alignment: Alignment.center,
 child: Scaffold(
  appBar: AppBar(
  title: Text('3D 變換Demo'),
  ),
  body: GestureDetector(
  onPanUpdate: (details) {
  setState(() {
  _rotateX += details.delta.dy * .01;
  _rotateY += details.delta.dx * -.01;
  });
  },
  child: Container(
  alignment: Alignment.center,
  color: Colors.white,
  child: Text('3D 變換Demo'),
  ),
  ),
 ));
 }
}

基本已經(jīng)實現(xiàn)了3D效果,但效果比較生硬,尤其垂直方向旋轉(zhuǎn)的時候遠(yuǎn)點和近點在屏幕上的寬度是一樣,

添加近大遠(yuǎn)小的效果:

Transform(
 transform: Matrix4.identity()
 ..setEntry(3, 2, 0.001)
 ..rotateX(_rotateX)
 ..rotateY(_rotateY),
 ...

翻書效果

上面的效果類似于翻書的效果。

實現(xiàn)的原理:

將圖片左右切割為兩部分,兩張圖片共分割為4個新的組件,如下圖,分別為1、2、3、4

代碼實現(xiàn):

_child1 = ClipRect(
 child: Align(
 alignment: Alignment.centerLeft,
 widthFactor: 0.5,
 child: child1,
 ),
);
_child2 = ClipRect(
 child: Align(
 alignment: Alignment.centerRight,
 widthFactor: 0.5,
 child: child1,
 ),
);

_child3 = ClipRect(
 child: Align(
 alignment: Alignment.centerLeft,
 widthFactor: 0.5,
 child: child2,
 ),
);

_child4 = ClipRect(
 child: Align(
 alignment: Alignment.centerRight,
 widthFactor: 0.5,
 child: child2,
 ),
);

將第一張圖片放在第二種圖片的上面,先旋轉(zhuǎn) 組件2 從 0度到 90度,然后再旋轉(zhuǎn) 組件3 從 -90度到0度,代碼實現(xiàn):

Row(
 mainAxisAlignment: MainAxisAlignment.center,
 children: <Widget>[
 Stack(
 children: [
 _child1,
 Transform(
  alignment: Alignment.centerRight,
  transform: Matrix4.identity()
  ..setEntry(3, 2, 0.001)
  ..rotateY(_animation1.value),
  child: _child3,
 ),
 ],
 ),
 Container(
 width: 3,
 color: Colors.white,
 ),
 Stack(
 children: [
 _child4,
 Transform(
  alignment: Alignment.centerLeft,
  transform: Matrix4.identity()
  ..setEntry(3, 2, 0.001)
  ..rotateY(_animation.value),
  child: _child2,
 )
 ],
 )
 ],
)

動畫控制器設(shè)置:

@override
void initState() {
 init();
 _controller =
 AnimationController(vsync: this, duration: Duration(seconds: 5))
 ..addListener(() {
  setState(() {});
 });
 _animation = Tween(begin: .0, end: pi / 2)
 .animate(CurvedAnimation(parent: _controller, curve: Interval(.0, .5)));
 _animation1 = Tween(begin: -pi / 2, end: 0.0).animate(
 CurvedAnimation(parent: _controller, curve: Interval(.5, 1.0)));
 _controller.forward();
 super.initState();
}

其中 child1, child2為兩種圖片,代碼如下:

_FlipUpDemoState(
 Container(
 width: 300,
 height: 400,
 child: Image.asset(
 'assets/images/b.jpg',
 fit: BoxFit.cover,
 ),
 ),
 Container(
 width: 300,
 height: 400,
 child: Image.asset(
 'assets/images/c.jpeg',
 fit: BoxFit.cover,
 ),
 ))

最后生成的效果就是開始的翻書效果。

上面是左右翻頁效果,同理換成上下翻頁效果:

@override
Widget build(BuildContext context) {
 return Scaffold(
 appBar: AppBar(),
 body: Column(
 mainAxisAlignment: MainAxisAlignment.center,
 children: <Widget>[
 Stack(
  children: [
  _upperChild1,
  Transform(
  alignment: Alignment.bottomCenter,
  transform: Matrix4.identity()
  ..setEntry(3, 2, 0.003)
  ..rotateX(_animation1.value),
  child: _upperChild2,
  ),
  ],
 ),
 SizedBox(
  height: 2,
 ),
 Stack(
  children: [
  _lowerChild2,
  Transform(
  alignment: Alignment.topCenter,
  transform: Matrix4.identity()
  ..setEntry(3, 2, 0.003)
  ..rotateX(_animation.value),
  child: _lowerChild1,
  )
  ],
 )
 ],
 ),
 );
}

到此這篇關(guān)于Flutter 實現(xiàn)酷炫的3D效果示例代碼的文章就介紹到這了,更多相關(guān)Flutter 實現(xiàn)酷炫的3D效果內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android Socket 線程連接openwrt與arduino單片機(jī)串口雙向通信的實例解析

    Android Socket 線程連接openwrt與arduino單片機(jī)串口雙向通信的實例解析

    這篇文章主要介紹了Android Socket 線程連接openwrt與arduino單片機(jī)串口雙向通信的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-11-11
  • Android 系統(tǒng)服務(wù)TelecomService啟動過程原理分析

    Android 系統(tǒng)服務(wù)TelecomService啟動過程原理分析

    這篇文章主要介紹了Android 系統(tǒng)服務(wù)TelecomService啟動過程原理分析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Android下Button實現(xiàn)圖文混排效果

    Android下Button實現(xiàn)圖文混排效果

    這篇文章主要為大家詳細(xì)介紹了Android下Button實現(xiàn)圖文混排效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Android UI 中的 ListView列表控件的示例

    Android UI 中的 ListView列表控件的示例

    本篇文章主要介紹了Android UI 中的 ListView列表控件的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02
  • Kotlin?協(xié)程的取消機(jī)制詳細(xì)解讀

    Kotlin?協(xié)程的取消機(jī)制詳細(xì)解讀

    這篇文章主要為大家介紹了Kotlin?協(xié)程的取消機(jī)制詳細(xì)解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • Android開發(fā)實現(xiàn)抽屜菜單

    Android開發(fā)實現(xiàn)抽屜菜單

    這篇文章主要為大家詳細(xì)介紹了Android開發(fā)實現(xiàn)抽屜菜單,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Android 5.0最應(yīng)該實現(xiàn)的8個期望

    Android 5.0最應(yīng)該實現(xiàn)的8個期望

    毫無疑問,Android 5 將是令人興奮的操作系統(tǒng),因為 Android4.0 至 4.4 版本之間并沒有顯著的差異,顯然谷歌會在 5.0 版本中進(jìn)行一些較大幅度的革新
    2016-01-01
  • Android實時文件夾創(chuàng)建方法

    Android實時文件夾創(chuàng)建方法

    這篇文章主要介紹了Android實時文件夾創(chuàng)建方法,涉及基于Activity實現(xiàn)文件實時查詢的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • flutter實現(xiàn)底部導(dǎo)航欄

    flutter實現(xiàn)底部導(dǎo)航欄

    這篇文章主要為大家詳細(xì)介紹了flutter實現(xiàn)底部導(dǎo)航欄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Android實現(xiàn)圓角彈框功能

    Android實現(xiàn)圓角彈框功能

    這篇文章主要介紹了Android實現(xiàn)圓角彈框功能,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-11-11

最新評論

涡阳县| 凤山市| 泽普县| 红原县| 昌平区| 嘉祥县| 宝丰县| 海宁市| 宜丰县| 长春市| 乐陵市| 东港市| 南召县| 寻乌县| 寿阳县| 安远县| 纳雍县| 四子王旗| 高密市| 富源县| 孝义市| 枣强县| 迁西县| 朝阳区| 滦南县| 文水县| 耿马| 河源市| 修武县| 奉新县| 怀柔区| 余干县| 衢州市| 斗六市| 鹤山市| 乐平市| 马尔康县| 宁夏| 江孜县| 宜兰县| 舟山市|