iOS 优化一:

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/pk_sir/article/details/72967123

硬件:iPhone 6s Plus,ios10.1
View的子控件:圆角性能测试
1,当屏幕中出现17个UIImageView 和 17个Lable,并对其进行圆角切割

    self.lab1.layer.masksToBounds = YES;
    self.lab1.layer.cornerRadius=5;
    self.imgView.image = [UIImage imageNamed:@"header.jpg"];
    self.imgView.layer.masksToBounds = YES;

这时,打开 Instruments 中的Code Animation
FPS 接近60,看上去没什么影响啊。
不急,再来17个圆角试试。

self.lab2.layer.masksToBounds = YES;
self.lab2.layer.cornerRadius=5;

恩恩,效果来了,再来17个圆角,FPS 在40-45之间。已经有点卡卡的感觉了,如果在加一些圆角,那么,效果就会很明显了,界面会出现卡顿,
有没有什么优化方法呢?有肯定有,只是我不知道,哈哈!
开玩笑的。请看下面哈:

    /*对于 UILable 这样的view 可以用一下方法设置圆角(不能设置View 的backGroundClolr,否则失效),不用去设置 maskSToBounds属性,
    但是:在cell 中使用这些方法,可能会出现cell 复用,在cell中频繁渲染 CGColor,很可能会出现混乱, */
    self.lab1.layer.backgroundColor = [UIColor cyanColor].CGColor;
    self.lab1.layer.cornerRadius = 5;

    self.lab2.layer.backgroundColor = [UIColor cyanColor].CGColor;
    self.lab2.layer.cornerRadius = 5;

    self.imgView.image = [UIImage imageNamed:@"header.jpg"];
    self.imgView.layer.masksToBounds = YES;
    self.imgView.layer.cornerRadius = 5;

虽然效率高(FPS接近60),但是视图混乱,还是舍弃
抛弃了上面的方法,再看下来:
明天见

猜你喜欢

转载自blog.csdn.net/pk_sir/article/details/72967123
今日推荐