iOS性能谈设置圆角的卡顿解决
假如在tableView的每个cell里有较多的圆角,因为在layer.corner...开销过大,会造成滑动的卡顿,解决方法是可以通过贝塞尔曲线进行绘制圆角,代码如下:
卡顿原因可以参考这篇文章:http://blog.ibireme.com/2015/11/12/smooth_user_interfaces_for_ios/
// 如下所示 // Get your image somehow UIImage *image = [UIImage imageNamed:@"image.jpg"]; // Begin a new image that will be the new image with the rounded corners // (here with the size of an UIImageView) UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0); // Add a clip before drawing anything, in the shape of an rounded rect [[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:10.0] addClip]; // Draw your image [image drawInRect:imageView.bounds]; // Get the image, here setting the UIImageView image imageView.image = UIGraphicsGetImageFromCurrentImageContext(); // Lets forget about that we were drawing UIGraphicsEndImageContext();
上述方法已经可以很完美的解决圆角过多的性能问题(PS:在5及以上手机圆角造成的卡顿其实可以忽略不计的=_=),优化狂魔如果想进一步的优化可以参考下面这篇文章。
扩展阅读:http://www.jianshu.com/p/bbb50b2cb7e6