大佬教程收集整理的这篇文章主要介绍了dart – 如何在图像内的任意点上旋转(并可能设置动画)图像?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
FractionalOffset
类指定旋转点的解决方案.
如果你不想动画,Transform
会做你想要的.
return new Transform( transform: new Matrix4.rotationZ(math.PI),alignment: FractionalOffset.bottomRight,child: child,);
如果你想要动画,RotationTransition
几乎可以做你想要的,除了对齐是不可配置的.您可以创建自己的可配置版本:
import 'dart:ui'; import 'dart:math' as math; import 'package:Flutter/material.dart'; void main() { runApp(new MaterialApp( title: "Rotation Demo",home: new RotateDemo(),)); } /// Animates the rotation of a widget around a pivot point. class PivotTransition extends AnimatedWidget { /// Creates a rotation transition. /// /// The [turns] argument must not be null. PivotTransition({ Key key,this.alignment: FractionalOffset.center,@required Animation<double> turns,this.child,}) : super(key: key,listenable: turns); /// The animation that controls the rotation of the child. /// /// If the current value of the turns animation is v,the child will be /// rotated v * 2 * pi radians before being painted. Animation<double> get turns => listenable; /// The pivot point to rotate around. final FractionalOffset alignment; /// The widget below this widget in the tree. final Widget child; @override Widget build(BuildContext context) { final double turnsValue = turns.value; final Matrix4 transform = new Matrix4.rotationZ(turnsValue * math.PI * 2.0); return new Transform( transform: transform,alignment: alignment,); } } class RotateDemo extends StatefulWidget { State createState() => new RotateDemoState(); } class RotateDemoState extends State<RotateDemo> with TickerProviderStatemixin { AnimationController _animationController; @override initState() { super.initState(); _animationController = new AnimationController( duration: const Duration(milliseconds: 3000),vsync: this,)..repeat(); } @override dispose() { _animationController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return new Scaffold( body: new Center( child: new PivotTransition( turns: _animationController,child: new Container( decoration: new BoxDecoration(BACkgroundColor: Colors.grey.shade200),width: 100.0,child: new Flutterlogo(style: FlutterlogoStyle.horizontal),),); } }
此示例围绕其右下角旋转Flutter徽标.
如果您喜欢冒险,可以向Flutter发送拉取请求,以使RotationTransition的对齐可配置.
以上是大佬教程为你收集整理的dart – 如何在图像内的任意点上旋转(并可能设置动画)图像?全部内容,希望文章能够帮你解决dart – 如何在图像内的任意点上旋转(并可能设置动画)图像?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。