只为探究日常开发过程中可能会出现的离屏渲染
本次实验仅探究使用使用alpha情况下
事先说明:查看离屏渲染是否产生通过模拟器中查看离屏渲染设置 - 发生离屏渲染时背景颜色为黄色
1、设置透明度是否一定会触发离屏渲染
/// 第一组不存在子view时
/// 结论不会触发离屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.alpha = 0.3;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
/// 第二组不存在子view时,存在背景色
/// 结论不会触发离屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.backgroundColor = [UIColor redColor];
parentView.alpha = 0.3;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
/// 第三组存在子view时,父View存在背景色
/// 结论不会触发离屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.backgroundColor = [UIColor redColor];
parentView.alpha = 0.3;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
UIView *childrenView = [[UIView alloc] init];
childrenView.frame = CGRectMake(0, 0, 40, 40);
[parentView addSubview:childrenView];
/// 第四组存在子view时,子View和父View存在背景色
/// 结论会触发离屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.backgroundColor = [UIColor redColor];
parentView.alpha = 0.3;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
UIView *childrenView = [[UIView alloc] init];
childrenView.frame = CGRectMake(0, 0, 40, 40);
childrenView.backgroundColor = [UIColor blackColor];
[parentView addSubview:childrenView];
/// 第五组存在子view时,子View和父View存在背景色且同时设置透明度
/// 结论会触发离屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.backgroundColor = [UIColor redColor];
parentView.alpha = 0.3;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
UIView *childrenView = [[UIView alloc] init];
childrenView.frame = CGRectMake(0, 0, 40, 40);
childrenView.alpha = 0.4;
childrenView.backgroundColor = [UIColor blackColor];
[parentView addSubview:childrenView];
/// 第六组存在子view时,子View和父View存在背景色,子View 透明度为0
/// 结论不会触发离屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.backgroundColor = [UIColor redColor];
parentView.alpha = 0.3;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
UIView *childrenView = [[UIView alloc] init];
childrenView.frame = CGRectMake(0, 0, 40, 40);
childrenView.alpha = 0;
childrenView.backgroundColor = [UIColor blackColor];
[parentView addSubview:childrenView];
/// 第七组存在子view时,子View和父View存在背景色,且背景色相同
/// 结论会触发离屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.backgroundColor = [UIColor redColor];
parentView.alpha = 0.3;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
UIView *childrenView = [[UIView alloc] init];
childrenView.frame = CGRectMake(0, 0, 40, 40);
childrenView.alpha = 0.3;
childrenView.backgroundColor = [UIColor redColor];
[parentView addSubview:childrenView];
/// 第八组存在子view时,仅子View存在背景色
/// 结论不会触发离屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.alpha = 0.3;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
UIView *childrenView = [[UIView alloc] init];
childrenView.frame = CGRectMake(0, 0, 40, 40);
childrenView.backgroundColor = [UIColor redColor];
[parentView addSubview:childrenView];
/// 第九组存在子view时,仅子View存在背景色,且子View设置透明度
/// 结论不会触发离屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.alpha = 0.3;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
UIView *childrenView = [[UIView alloc] init];
childrenView.frame = CGRectMake(0, 0, 40, 40);
childrenView.backgroundColor = [UIColor redColor];
childrenView.alpha = 0.3;
[parentView addSubview:childrenView];
通过上述实验得到结论如下:
1、通过1、2组实验可得,设置透明度时不一定出现离屏渲染
2、通过3、4、8、9组实验可得,当父view设置背景色和透明度,子View设置背景色时才会出现离屏渲染
3、通过3、4,5、6组实验可得,当父view设置背景色和透明度,当子View设置透明度伟0不会出现离屏渲染