UICollisionBehavior - custom form for UIView collision

I'm trying to figure out how to use UIKit Dynamics to successfully collide two UIViews that have custom border shapes.

The simplest example I can come up with to explain my question is for two circles to collide (given their round corners) instead of their square border.

I am sure I saw this somewhere, but I can not find the documentation or discussion on this issue from an official source.

+3
source share
1 answer

, , UIKit Dynamics iOS 7. , , UIDynamicItem (UIView does). , , bounds, CGRect. .

Bezier , , , , . DynamicsCatalog Xcode, , .

BumperView, UIView. BumperView.m drawRect:

#define LINE_WIDTH 2.0
- (void)drawRect:(CGRect)rect
{
    UIBezierPath *ovalPath = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(self.bounds, LINE_WIDTH/2, LINE_WIDTH/2)];
    [[UIColor blueColor] setStroke];
    [[UIColor lightGrayColor] setFill];
    ovalPath.lineWidth = LINE_WIDTH;
    [ovalPath stroke];
    [ovalPath fill];
}

BumperView . bumper APLItemPropertiesViewController.m, BumperView. viewDidAppear : collisionBehavior:

UIBezierPath *bumperPath = [UIBezierPath bezierPathWithOvalInRect:self.bumper.frame];
[collisionBehavior addBoundaryWithIdentifier:@"Bumper" forPath:bumperPath];

" ", , .

+5

All Articles