只為探究日常開(kāi)發(fā)過(guò)程中可能會(huì)出現(xiàn)的離屏渲染
本次實(shí)驗(yàn)僅探究使用cornerRadius & masksToBounds 切圓角
事先說(shuō)明:查看離屏渲染是否產(chǎn)生通過(guò)模擬器中1、切圓角是否一定會(huì)觸發(fā)離屏渲染 - 多組對(duì)照實(shí)驗(yàn)(以下代碼都可以拿去自己嘗試,事實(shí)不會(huì)騙人)
/// 第一組 不存在子view時(shí)
/// 結(jié)論不會(huì)觸發(fā)離屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.layer.cornerRadius = 50;
parentView.layer.masksToBounds = YES;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
/// 第二組存在子view時(shí)
/// 結(jié)論不會(huì)觸發(fā)離屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.layer.cornerRadius = 50;
parentView.layer.masksToBounds = YES;
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時(shí),parentView存在背景色
/// 結(jié)論不會(huì)觸發(fā)離屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.backgroundColor = [UIColor redColor];
parentView.layer.cornerRadius = 50;
parentView.layer.masksToBounds = YES;
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時(shí),parentView和子view同時(shí)存在背景色
/// 結(jié)論會(huì)觸發(fā)離屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.backgroundColor = [UIColor redColor];
parentView.layer.cornerRadius = 50;
parentView.layer.masksToBounds = YES;
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時(shí)蒿柳,僅子View背景色存在崖蜜,且被切割到
/// 結(jié)論會(huì)觸發(fā)離屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.layer.cornerRadius = 50;
parentView.layer.masksToBounds = YES;
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時(shí)乒疏,僅子View存在背景色且子View不被切割
/// 結(jié)論不會(huì)觸發(fā)離屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.layer.cornerRadius = 50;
parentView.layer.masksToBounds = YES;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
UIView *childrenView = [[UIView alloc] init];
childrenView.frame = CGRectMake(25, 25, 40, 40);
childrenView.backgroundColor = [UIColor blackColor];
[parentView addSubview:childrenView];
/// 第七組存在子view時(shí)盖高,父view和子View同時(shí)存在背景色且子View不被切割
/// 結(jié)論會(huì)觸發(fā)離屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.backgroundColor = [UIColor redColor];
parentView.layer.cornerRadius = 50;
parentView.layer.masksToBounds = YES;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
UIView *childrenView = [[UIView alloc] init];
childrenView.frame = CGRectMake(25, 25, 40, 40);
childrenView.backgroundColor = [UIColor blackColor];
[parentView addSubview:childrenView];
/// 第八組存在子view時(shí)听想,父view和子View同時(shí)存在背景色且相同邦马,且子View不被切割
/// 結(jié)論會(huì)觸發(fā)離屏渲染
UIView *parentView = [[UIView alloc] init];
parentView.backgroundColor = [UIColor redColor];
parentView.layer.cornerRadius = 50;
parentView.layer.masksToBounds = YES;
parentView.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:parentView];
UIView *childrenView = [[UIView alloc] init];
childrenView.frame = CGRectMake(25, 25, 40, 40);
childrenView.backgroundColor = [UIColor redColor];
[parentView addSubview:childrenView];
通過(guò)上述實(shí)驗(yàn)得到結(jié)論如下:
1贱鼻、通過(guò)1、2組實(shí)驗(yàn)得出滋将,存在子View并切割子View時(shí)不一定會(huì)出現(xiàn)離屏渲染
2邻悬、通過(guò)3、4随闽、7父丰、8組實(shí)驗(yàn)得出,存在子View且同時(shí)存在顏色時(shí)一定會(huì)出現(xiàn)離屏渲染
3掘宪、通過(guò)5蛾扇、6組實(shí)驗(yàn)得出,僅子View存在背景顏色且被切割時(shí)一定會(huì)出現(xiàn)離屏渲染