我是 iOS 新手。我正在制作一个聊天应用程序。我正在使用 UITableView
显示消息聊天(一个单元格 - 一条消息)。
在每个单元格中,我将在 2、3 或 4 角(如 Facebook 聊天)中舍入消息
对于 rounder,我在每个 Tableview Cell
的 layoutSubView
中使用 UIBezierPath
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft) cornerRadii:CGSizeMake(3.0, 3.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.messageView.layer.mask = maskLayer;
问题是,当布局第一次初始化时,一切正常,但是当我滚动一些单元格时有错误的舍入(我发现问题是滚动 self.messageView.bounds
返回错误的值所以 UIBezierPath
画错了角)但我不知道为什么
我怎样才能防止它发生?
或者我可以用另一种方法在没有 UIBezierPath
的情况下舍入 View(我用谷歌搜索但我只找到一种舍入 UIView 的方法是使用 UIBezierPath
:( )?
任何帮助将不胜感激
最佳答案
我有一个类似的问题,并通过在 tableView:willDisplayCell:forRowAtIndexPath
中移动我的圆角代码来修复它,这将允许 Cocoa 正确调整大小。
关于ios - 滚动时 UIBezierPath 问题的舍入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36420899/