简体   繁体   English

如何绘制一个与UICollisionBehavior相似的圆圈UIView?

[英]How do I draw a circle UIView that acts like one with UICollisionBehavior?

In my app, I'm currently drawing a basic view, and then I'm trying to round it's corners using a CAShapeLayer, but the UICollisionBehavior still reacts like it's a square that is drawn. 在我的应用程序中,我正在绘制一个基本视图,然后我尝试使用CAShapeLayer来绕过它的角落,但是UICollisionBehavior仍然会像它是一个绘制的正方形一样做出反应。

Here's an example of my code 这是我的代码示例

  UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                           byRoundingCorners:UIRectCornerAllCorners
                                                 cornerRadii:radiiSize];

// Mask the container view’s layer to round the corners.
CAShapeLayer *cornerMaskLayer = [CAShapeLayer layer];
[cornerMaskLayer setPath:path.CGPath];
self.containerView.layer.mask = cornerMaskLayer;
self.containerView.layer.allowsEdgeAntialiasing = YES;

Just do this rather than use UIBezierPath 只需这样做而不是使用UIBezierPath

self.containerView.layer.cornerRadius = [Radius is half the height/width];
self.containerView.clipsToBounds = YES;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM