我已经继承MaterialView
并覆盖drawRect
了一个自定义视图,然后我将其添加为我的 tableViewFooter。正如标题所说,我无法深入工作。我已经在不同的层/视图上搞砸了clipsToBounds
,但没有成功。masksToBounds
它是 UIViewController 内部的一个 tableView ,只是为了让我的代码更清晰。
let receiptEdge = ReceiptEdge(frame: CGRect(x: 0, y: 0, width: self.view.w, height: 30))
receiptEdge.backgroundColor = .whiteColor()
receiptEdge.depth = MaterialDepth.Depth5
//What I've tried messing with for an hour
receiptEdge.clipsToBounds = false
receiptEdge.layer.masksToBounds = true
self.tableView.clipsToBounds = false
self.view.clipsToBounds = false
self.view.layer.masksToBounds = true
self.tableView.layer.masksToBounds = true
self.tableView.tableFooterView = receiptEdge
我的子类代码ReceiptEdge
override func prepareView() {
super.prepareView()
let rect = self.frame
let path = UIBezierPath()
let receiptEdgeSize = CGFloat(rect.width / 75)
var x = CGFloat(-receiptEdgeSize / 2)
let y = rect.size.height / 2
path.moveToPoint(CGPoint(x: x, y: y))
while x < rect.width {
x += receiptEdgeSize
path.addLineToPoint(CGPoint(x: x, y: y))
x += receiptEdgeSize
path.addArcWithCenter(CGPoint(x: x, y: y), radius: receiptEdgeSize, startAngle: CGFloat(M_PI), endAngle: CGFloat(0), clockwise: true)
x += receiptEdgeSize
}
path.addLineToPoint(CGPoint(x: x, y: CGFloat(0)))
path.addLineToPoint(CGPoint(x: 0, y: 0))
path.addLineToPoint(CGPoint(x: 0, y: y))
let layer = CAShapeLayer()
layer.path = path.CGPath
self.layer.mask = layer
self.visualLayer.mask = layer
self.visualLayer.backgroundColor = UIColor.blueColor().CGColor
self.layer.shadowColor = UIColor.redColor().CGColor
}
没有显示深度的屏幕截图
提前感谢比我更了解图层的人!这是一个视图示例,我在其中深入研究了MaterialTableViewCell
using的子类MaterialDepth.Depth2
在这里,我没有设置任何图层或路径self.layer
。有阴影,但视图或阴影没有剪裁到可视层。将 shadowColor 设置为红色,以便您可以看到差异。