UIImageViews 之间的碰撞检测 [英] Collision detection between UIImageViews

查看:34
本文介绍了UIImageViews 之间的碰撞检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩 UIKit 动态,我有两个带有 UICollisionBehavior 的 UIImageViews,当两个视图碰撞时它的委托被触发,问题是,如果图像是圆形,则框架是正方形,甚至框架都是碰撞那不是我真正想要的.

I'm playing around with UIKit dynamics, I have two UIImageViews with an UICollisionBehavior, it's delegate is fired when the two views collide, the problem is, if the image is a circle the frame is a square and even the frames are colliding that's not what I really want.

如何检测碰撞:

我希望被检测到的方式:

How I want to be detected:

是否有解决方法来实现这一目标?提前致谢.

Is there a workaround to achieve this?. Thank you in advance.

更新:图像不是圆圈,所以我可能不得不使用 UIDynamicItemCollisionBoundsTypePath 并将我的 UIImage 转换为 UIBezierPath

UPDATE: The images aren't circles, so I'll probably have to use UIDynamicItemCollisionBoundsTypePath and transform my UIImage to a UIBezierPath

推荐答案

你应该创建一个 UIImageView 的子类并实现:

You should make a subclass of UIImageView and implement:

override var collisionBoundsType: UIDynamicItemCollisionBoundsType {
        return .Ellipse
    }

-(UIDynamicItemCollisionBoundsType) collisionBoundsType {
    return UIDynamicItemCollisionBoundsTypeEllipse;
}

有关详细信息,请参阅此处

这篇关于UIImageViews 之间的碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆