【发布时间】:2012-07-01 00:48:53
【问题描述】:
所以我有一个名为 fallingBall 的 UIView,它目前与我的名为 theBlockView 的 UIView 很好地碰撞。我正在使用CGRectIntersectsRect(theBlockView.frame, fallingBall.frame) 来检测这种碰撞。
这一切都很好,所以现在我希望我的fallingBall 实际上是圆形的,我还希望theBlockView 的顶角是圆形的。为此,我使用了以下代码:
//round top right-hand corner of theBlockView
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:theBlockView.bounds
byRoundingCorners:UIRectCornerTopRight
cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = theBlockView.bounds;
maskLayer.path = maskPath.CGPath;
theBlockView.layer.mask = maskLayer;
//round the fallingBall view
[[fallingBall layer] setCornerRadius:30];
但是,有趣的是,虽然它们看起来很圆润,但视图仍然是矩形。
所以我的问题是:我怎样才能让CGRectIntersectsRect 将它们视为它们看起来的形状?是否有一个功能相同但使用视图的 alpha 来检测碰撞的功能?
感谢您的宝贵时间!
【问题讨论】:
标签: objective-c ios cocoa-touch collision-detection quartz-2d