IOS UIImageView的旋转平移缩放

    UIImage *image = [UIImage imageNamed:@"1.png"];
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    [imageView setFrame:CGRectMake(50, 50, 200, 200)];
    
    [self.view addSubview:imageView];
    
    // 1. 圆角半径
    // 提示,在imageView中,图层不止一个,如果要实现圆角效果,需要设置一个遮罩属性
    // masksToBounds属性可以让imageView中的所有子图层跟随imageView一起变化
    imageView.layer.cornerRadius = 50.0f;
    [imageView.layer setMasksToBounds:YES];

    // 2. 阴影
    // 提示,如果设置了masksToBounds属性,imageView的阴影效果无效
    [imageView.layer setShadowColor:[UIColor redColor].CGColor];
    [imageView.layer setShadowOffset:CGSizeMake(10.0, 10.0)];
    [imageView.layer setShadowOpacity:1.0];
    
    // 3. 边框
    [imageView.layer setBorderColor:[UIColor blueColor].CGColor];
    [imageView.layer setBorderWidth:3.0f];
    
    // 4. 形变属性,在CALayer中的形变属性是3D的,不再是2D的
    // 提示,形变参数使用set方法时,只能应用一种形变
    // 1> 平移属性(向上移动100个点)
//    [imageView.layer setTransform:CATransform3DMakeTranslation(0, -100, 0)];
//    // 2> 缩放属性
//    [imageView.layer setTransform:CATransform3DMakeScale(0.5, 1.0, 1.0)];
//    // 3> 旋转属性
//    // 提示:通常在旋转时指定z轴即可,要延哪个轴旋转,指定一个数值1.0即可
//    // 图像本身没有厚度,如果按照x或y旋转90度,图像是不可见的。
//    [imageView.layer setTransform:CATransform3DMakeRotation(M_PI_2, 0, 0, 1.0)];

    // 5. 利用keyPath设置形变,可以组合使用,但是记住不要输错
    // 提示,在文档中输入transform3D可以找到对应的transform keyPath
    
    [UIView animateWithDuration:3.0 animations:^{
        // 1)平移
        [imageView.layer setValue:@-100 forKeyPath:@"transform.translation.y"];
        // 2) 缩放
        [imageView.layer setValue:@0.5 forKeyPath:@"transform.scale"];
        // 3) 旋转
        [imageView.layer setValue:@M_PI_2 forKeyPath:@"transform.rotation.z"];
    }];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值