CAReplicatorLayer实现倒影效果实例

在storyboard创建如下图的控件

将根控制器的View改为一个自定义的UIView

#import "MyUIView.h"

@implementation MyUIView

+ (Class)layerClass
{
    return [CAReplicatorLayer class];
}

@end

这样做的目的是让根控制器的View根层是一个复制层

#import "ViewController.h"

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    CAReplicatorLayer *replicatorLayer = (CAReplicatorLayer*)self.view.layer;

    //包括本身的内容在内创建2份子层的内容
    replicatorLayer.instanceCount = 2;

    //调整颜色及透明度
    replicatorLayer.instanceRedOffset -= 0.3;
    replicatorLayer.instanceGreenOffset -= 0.3;
    replicatorLayer.instanceBlueOffset -= 0.3;
    replicatorLayer.instanceAlphaOffset -= 0.4;

    //做垂直翻转形变
    replicatorLayer.instanceTransform = CATransform3DMakeRotation(M_PI, 1, 0, 0);
}

@end

results matching ""

    No results matching ""