给视图添加倒影效果(包括图片视图)
原理剖析:
在视图中的主图层(CALayer)再添加一个子图层,确定其frame(位置),copy一份主图层的内容然后绕Y轴翻转一下---
const CGFloat kReflectPercent = 0.25f;
const
CGFloat kReflectOpacity = 0.7f;
const
CGFloat kReflectDistance = 5.0f;
CALayer
*reflectionLayer = [CALayer layer];
reflectionLayer.contents = [self.image layer].contents;
reflectionLayer.opacity = kReflectOpacity;
reflectionLayer.frame =
CGRectMake(0.0f,self.image.frame.size.height+kReflectDistance,self.image.frame.size.width,self.image.frame.size.height*kReflectPercent);
//倒影层框架设置,其中高度是原视图的百分比
CATransform3D stransform =
CATransform3DMakeScale(1.0f,-1.0f,1.0f);
//CATransform3D transform =
CATransform3DTranslate(stransform,0.0f,0.0f,0.0f);
reflectionLayer.transform = stransform;
reflectionLayer.sublayerTransform =
reflectionLayer.transform;
[[self.image
layer] addSublayer:reflectionLayer];
const CGFloat kReflectPercent = 0.25f;
网络上志同道合,我们一起学习网络安全,一起进步,QQ群:694839022