tableView滑动很卡的原因

最近发现项目中自己写的列表在滑动时有些卡,而同事的列表很顺畅,两个列表显示的内容基本相同,都是几个imageView和几个label还有1个按钮,功能上主要是异步加载图片.

经过分析查找,最终发现问题的根源在于图标的圆角处理方式:

我的列表的cell在处理圆角时直接使用 :
iconImageView = [[UIImageView alloc]init];

iconImageView.layer.cornerRadius = 12;

而同事处理圆角时使用CAShapeLayer处理:

@interface CollectionViewCellImageView : UIImageView

@property (nonatomic, strong) CAShapeLayer * maskLayer;
@property (nonatomic, assign) CGFloat   maskCornerRadius;
@property (nonatomic, strong) NSURL * url;

@end

@implementation CollectionViewCellImageView

- (instancetype)init
{
    self = [super init];
    if (self) {
        _maskLayer = [CAShapeLayer new];
        _maskLayer.fillColor = [UIColor whiteColor].CGColor;
        _maskLayer.fillRule = kCAFillRuleEvenOdd;
        [self.layer addSublayer:_maskLayer];
    }
    return self;
}

- (void)setMaskCornerRadius:(CGFloat)maskCornerRadius{
    _maskCornerRadius = maskCornerRadius;
    _maskLayer.borderWidth = 0.5;
    _maskLayer.borderColor = hllColor(120, 120, 120, 0.3).CGColor;
    _maskLayer.cornerRadius = maskCornerRadius;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _maskLayer.frame = self.layer.bounds;
    UIBezierPath* path = [UIBezierPath bezierPathWithRect:self.layer.bounds];
    [path appendPath:[UIBezierPath bezierPathWithRoundedRect:self.layer.bounds cornerRadius:self.maskCornerRadius]];
    _maskLayer.path = path.CGPath;
    
}

@end


创建UIImageView的子类,使用时

iconImageView = [[CollectionViewCellImageView alloc]init];

        iconImageView.maskCornerRadius = 12.0f;


修改后,列表滑动非常流畅.



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
在QML中,要实现TableView的水平滑动,可以使用ScrollView来包裹TableView,并设置水平滚动条的属性。下面是一个示例代码: ``` import QtQuick 2.6 import QtQuick.Window 2.2 import QtQuick.Controls 1.4 import QtQuick.Controls.Styles 1.4 import QtQuick.Layouts 1.12 Window { id: window visible: true width: 600 height: 480 title: qsTr("QML自定义组件") ScrollView { id: scrollView anchors.fill: parent ScrollBar.horizontal.policy: ScrollBar.AlwaysOn TableView { id: phoneTable width: scrollView.width height: scrollView.height TableViewColumn { role: "name" title: "Name" width: 100 elideMode: Text.ElideRight } TableViewColumn { role: "cost" title: "Cost" width: 100 } TableViewColumn { role: "manufacturer" title: "Manufacturer" width: 140 } model: ListModel { id: phoneModel ListElement { name: "iphone 5" cost: "4900" manufacturer: "Apple" } ListElement { name: "iphone 8" cost: "4900" manufacturer: "Apple" } ListElement { name: "iphone 6" cost: "4900" manufacturer: "Apple" } ListElement { name: "iphone 7" cost: "4900" manufacturer: "Apple" } } focus: true } } } ``` 在这个示例中,我们将TableView放在了ScrollView中,并设置了水平滚动条的属性为AlwaysOn,这样就可以实现水平滑动了。 #### 引用[.reference_title] - *1* [QML TableView 使用详解](https://blog.csdn.net/u013873761/article/details/125064741)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [QML学习十七:TableView的简单使用](https://blog.csdn.net/weixin_38807927/article/details/125348247)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老槽哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值