我试图在UICollectionView
我有UIView
contentView ,其中包含我的UICollectionView
。如果我将UICollectionView
的cornerRadius设置为true并将clipsToBound设置为true,则除了将所有4个角落进行舍入之外,这是有效的。
所以看起来我需要应用UIBezierPath
但是一旦我这样做,我遇到了问题:
UIBezierPath
应用于UICollectionView
本身,我只能看到我的第一个单元格,当我滚动到第二个单元格时,我看不到任何内容。 [
[UIBezierPath bezierPathWithRoundedRect:self.collectionView.bounds
byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(9.0,
9.0)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.collectionView.bounds;
maskLayer.path = maskPath.CGPath;
self.collectionView.layer.mask = maskLayer;
UIBezierPath
应用于 contentView ,与上述相同,但我将 self.collectionView 替换为 self.contentView < / strong>,角落根本不圆。答案 0 :(得分:0)
如何舍入您的collectionView所在的视图?
这样的事情:
let viewFrame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
let corners: UIRectCorner = .topLeft
let path = UIBezierPath(
roundedRect: viewFrame,
byRoundingCorners: corners,
cornerRadii: CGSize(width: 50, height: 50))
let maskLayer = CAShapeLayer()
maskLayer.frame = viewFrame
maskLayer.path = path.cgPath
view.layer.mask = maskLayer
答案 1 :(得分:0)
只要父视图不是我的第一个/顶部视图,就可以在UIBezierPath
父容器上设置UICollectionView
。我必须在我的热门UIView
添加另一个UIView
roundContainerView 。
UIView ( Top view. contentView )
|- UIView ( roundContainerView ) apply UIBezierPath here
|- UICollectionView ( collectionView )