美文网首页
CATransform3D 使用

CATransform3D 使用

作者: 阳vs阴 | 来源:发表于2017-02-08 13:31 被阅读0次

    struct CATransform3D

    {

    CGFloat m11(x轴缩放), m12(y轴切变), m13, m14(x轴拉伸);

    CGFloat m21(x轴切变), m22(y轴缩编), m23, m24(向y轴拉伸);

    CGFloat m31, m32, m33, m34;

    CGFloat m41(x轴平移), m42(y轴平移), m43(z轴平移), m44(放大);

    };

    举例:

    对照图

    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

    img.image = [UIImage imageNamed:@"11"];

    [self.view addSubview:img];

    修改图

    UIImageView *caimg = [[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 100, 100)];

    caimg.image = [UIImage imageNamed:@"11"];

    [self.view addSubview:caimg];

    1、平行移动

    CATransform3DMakeTranslation(tx,ty,tz)

    tx:x轴方向移动,右移为正数

    ty:y轴方向移动,下移为正数

    tz:z轴方向移动,外移为正数

    CATransform3D translation = CATransform3DMakeTranslation(0.0, 80.0, 5.0);

    caimg.layer.transform = translation;

    2、缩放

    CATransform3DMakeScale(CGFloat sx, CGFloat sy, CGFloat sz)

    sx:x轴方向缩放,大于1放大。小于1缩小

    sy:y轴方向缩放,大于1放大。小于1缩小

    sz:z轴方向缩放,大于1放大。小于1缩小

    CATransform3D scale = CATransform3DMakeScale(2, 2, 5);

      caimg.layer.transform = scale;

    3、旋转

    CATransform3DMakeRotation (CGFloat angle, CGFloat x,CGFloat y, CGFloat z)

    angle:旋转角度

    x:围绕x轴旋转,取值范围-1~1

    y:围绕y轴旋转,取值范围-1~1

    z:围绕z轴旋转,取值范围-1~1

    CATransform3D rotation = CATransform3DMakeRotation(M_PI/3, 1, 1, 1); caimg.layer.transform = rotation;

    4、复合行

    CATransform3DIsIdentity (CATransform3D t)

    t:CATransform3D类型,可以附加

    CATransform3DTranslate (CATransform3D t, CGFloat tx,

    CGFloat ty, CGFloat tz)

    CATransform3DScale (CATransform3D t, CGFloat sx,

    CGFloat sy, CGFloat sz)

    相关文章

      网友评论

          本文标题:CATransform3D 使用

          本文链接:https://www.haomeiwen.com/subject/nbpvittx.html