Reflection of iOS Animation
1. Result Display
2. Implementation ideas
1. Use the copy layer to create a UIImageView to display the image, and then copy the UIImageView.
Note:The copy layer can only copy child layers, but the UIImageView has only one main layer and has no child layers. Therefore, you cannot directly copy the UIImageView.
2. correct practice: add the UIImageView to a UIView, and copy the UIView layer to copy the UIImageView.
Note:By default, control A is A child control of control B. The layer of control A is the child layer of control B.
3. If there is a problem, the default UIView layer is not the copy layer. We want to change the UIView layer to the copy layer and rewrite the + layerClass method.
+ (Class)layerClass{ return [CAReplicatorLayer class];}
4. reflection effect: rotate the copied image to 180 degrees and then pan down. It is best to offset the image first and rotate it.
CAReplicatorLayer * layer = (CAReplicatorLayer *) self. v. layer; layer. instanceCount = 2; // The first Y axis offset CATransform3D transform = CATransform3DMakeTranslation (0, self. v. bounds. size. height, 0); // rotate transform = CATransform3DRotate (transform, M_PI, 1, 0, 0); // set the deformation layer of the replication layer. instanceTransform = transform; // sets the color channel offset, which is equal to the offset of the previous point, that is, the shadow effect layer. instanceRedOffset =-0.1; layer. instanceGreenOffset =-0.1; layer. instanceBlueOffset =-0.1; layer. instanceAlphaOffset =-0.1;
3. Demo implementation