我正在工作或项目中,我必须给角落从左上角和右上角查看。我正在为此使用自动布局。我的 View 宽度是 296。这是设计
根据我在 tableview 第一个单元格中的设计,我的代码到 selected view
的圆角 let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath)
let view_ = cell.viewWithTag(10)! as UIView
let maskLayer : CAShapeLayer = CAShapeLayer()
let maskpath = UIBezierPath(roundedRect: view_.bounds, byRoundingCorners: [.TopLeft,.TopRight], cornerRadii: CGSizeMake(10, 10))
maskLayer.frame = view_.bounds;
maskLayer.path = maskpath.CGPath;
view_.layer.mask = maskLayer
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell
但我的问题是我得到了这个输出
我给 view_.bounds
但我不知道为什么它采用该 View 的原始帧值。在像 iphone 4s 和 5 这样的小型设备中,它可以完美地提供输出,但在大型设备中它会出现问题,如屏幕截图。
请帮帮我
最佳答案
问题是您运行代码的时间太早了。您的代码取决于我们知道 view_.bounds
的假设:
let maskpath = UIBezierPath(roundedRect: view_.bounds, byRoundingCorners: [.TopLeft,.TopRight], cornerRadii: CGSizeMake(10, 10))
maskLayer.frame = view_.bounds;
但在您的代码运行时,该值尚未最终确定。这里要记住的是, View 在放入界面时会调整大小。您希望将代码推迟到view_.bounds
达到其最终值(也称为布局)。
关于ios - 左右边的圆角不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40602685/