具有非矩形范围的UIDynamicItem [英] UIDynamicItem with non-rectangular bounds
问题描述
所以我正在研究UIKit Dynamics,我遇到的一个问题是,如果我想使用自定义的drawRect:
创建一个UIView(例如,假设我要绘制一个三角形),似乎有无法指定要用于UICollisionBehavior的UIView(或UIDynamicItem)的路径.
So I'm looking into UIKit Dynamics and the one problem I have run into is if I want to create a UIView with a custom drawRect:
(for instance let's say I want to draw a triangle), there seems to be no way to specify the path of the UIView (or rather the UIDynamicItem) to be used for a UICollisionBehavior.
我的目标确实是使屏幕上的多边形彼此碰撞,而碰撞的方式恰恰是人们所期望的.
My goal really is to have polygons on the screen that collide with one another exactly how one would expect.
我想出了一种将多个视图拼接在一起的解决方案,但这似乎对我想要的东西来说是过大了.
I came up with a solution of stitching multiple views together but this seems like overkill for what I want.
是否有一些简单的方法可以做到这一点,或者我真的必须将视图拼接在一起吗?
Is there some easy way to do this, or do I really have to stitch views together?
丹
推荐答案
观看有关此主题的WWDC 2013视频.它们非常清楚:为了提高效率和速度,在碰撞期间仅视域的(矩形)边界很重要.
Watch the WWDC 2013 videos on this topic. They are very clear: for the sake of efficiency and speed, only the (rectangular) bounds of the view matter during collisions.
编辑,在iOS 9中,动态项目可以具有自定义的碰撞边界.您可以具有由框架决定的矩形,由框架决定的椭圆或自定义形状-逆时针凸的简单封闭UIBezierPath.相关属性collisionBoundsType
和(对于自定义形状)collisionBoundingPath
是只读的,因此您必须子类化才能设置它们.
EDIT In iOS 9, a dynamic item can have a customized collision boundary. You can have a rectangle dictated by the frame, an ellipse dictated by the frame, or a custom shape — a convex counterclockwise simple closed UIBezierPath. The relevant properties, collisionBoundsType
and (for a custom shape) collisionBoundingPath
, are read-only, so you will have to subclass in order to set them.
这篇关于具有非矩形范围的UIDynamicItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!