微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flutter技术实践8transform矩阵转换

Transform的主要作用是矩阵转换,在Container中矩阵变换就是使用了Transform,同事Transform也可以对child做平移、旋转、及缩放等操作。

属性 类型 说明
transform Matrix4 一个4X4的矩阵,不难发现,其他平台的变换矩阵也都是思维的。一些复合操作,仅靠三维是不够的,必须采用额外的一维来补充。
origin Offset 一旋转点,相对于左上角定点的偏移,认旋转点是左上角的顶点。
alignment AlignmentGeometry 对其方式
transformHitTests bool 点击区域是否也做相应的改变

示例代码

import 'package:Flutter/material.dart';

/**
 * Transform矩阵转换示例
 */
void main(){
  runApp(new MaterialApp(
    title: 'Transform矩阵转换示例',
    home: new MyApp(),
  ));
}

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // Todo: implement build
    return new Scaffold(
      appBar: AppBar(
        title: new Text('Transform矩阵转换示例'),
      ),
      body: new Center(
        child: Container(
          color: Colors.grey,
          child: Transform(
            alignment: Alignment.topRight,
            transform: Matrix4.rotationZ(0.3),
            child: Container(
              padding: const EdgeInsets.all(8.0),
              color: const Color(0xFFE8581C),
              child: const Text('Transform矩阵转换'),
            ),
          ),
        ),
      ),
    );
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐