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

608 views Asked by At

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.

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;
1

There are 1 answers

8
Ethan Fang On

Just do this rather than use UIBezierPath

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