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"];
}];
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"];
}];