iOS性能谈设置圆角的卡顿解决

本文介绍了一种在iOS开发中优化TableView中大量圆角图片性能的方法,通过使用贝塞尔路径来替代传统的圆角处理方式,有效避免了滑动卡顿的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

假如在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

 

转载于:https://www.cnblogs.com/zhaoyunboy/p/how-to-clip-imageView-cornerradius.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值