设置 subview 的layer.cornerRadius后,iOS UITableView滚动不流畅

标签 ios objective-c uitableview

<分区>

我正在使用 UITableView 制作一个日历 View (见下图),每个 UITableViewCell 代表一个月和几个 subview ,每个 subview 意味着有一天让我们称之为DayView,每个 DayView 都包含一个 subview UILabel 来显示一个月中的第几天。到目前为止,一切似乎都很好,UITableView 的滚动很流畅。但是在我将这一行添加到 DayView- (instancetype)initWithFrame:(CGRect)frame 之后:

self.layer.cornerRadius = 5.0;

UITableView 的帧率在滚动时变得非常低。它根本赶不上我的手指。那么最可能的原因是什么?

请问,遇到这种问题应该怎么办?

谢谢。

编辑:

cellForRowAtIndexPath 方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *monthCellIdentifier = @"MonthCell";
    OPCalendarPageView *cell = [tableView dequeueReusableCellWithIdentifier:monthCellIdentifier];
    cell.manager = _manager;
    cell.date = [self dateForIndexPath:indexPath];
    return cell;
}

我正在使用图书馆 JTCalendar , OPCalendarPageViewJTCalendarPageView 的自定义版本,只是在月份的第一天上方添加了一个月份标签。

screenshot

最佳答案

首先,请多提一点,比如你的 subview 的场景,或者你设置的其他属性,比如 border-width 或 masktobound 或 cliptobound 等,而不是设置角半径。

其次, 我不确定,但我已经通过设置以下行解决了我的问题

self.layer.masksToBounds = YES;

或者如果此解决方案不起作用,请尝试以下链接,其中 fknrdcls关于保护角半径对 uitableview 的负面影响,以适当的方式给出了很好的答案。
uitableview 基本上是 uiscrollview 的子类,所以下面的解决方案可能会解决您的问题。

UILabel layer cornerRadius negatively impacting performance

关于设置 subview 的layer.cornerRadius后,iOS UITableView滚动不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32786999/

相关文章:

ios - OBJC @selector 在另一个实现中不起作用

ios - 带有 WKWebView 单元格的滚动 UICollectionView 的 UITableView

ios - 为什么我的可旋转轮控件有时会向错误的方向旋转?

ios - 在ios中获取正确的状态栏颜色

ios - 从主视图 Controller 访问模态视图 Controller 中 UITextField 的文本

objective-c - 我无法打开邮件应用程序?

ios - TableView 单元格错误 - iOS/Swift

ios - 滚动时如何将 SearchBar 固定为 UITableView 的标题?

ios - 是否可以通过 iOS SDK 在 Facebook 请求对话框中显示所有好友?

ios - 从 Windows 移动到 mac 后,M1 上的 Flutter : GoogleMapsBase & Flutter. h 未发现错误