UIDynamicItem手动更新转换 [英] UIDynamicItem update transform manually
问题描述
我知道外部更改为中心
,界限
和转换$ c在$ code> UIDynamicItem
s init之后将忽略$ c>。
I know that external change to center
, bounds
and transform
will be ignored after UIDynamicItem
s init.
但是我需要手动更改转换
UIView
在 UIDynamicAnimator
系统中。
But I need to manually change the transform
of UIView
that in UIDynamicAnimator
system.
每当我更改转换
时,它都会立即被覆盖。
Every time I change the transform
, it will be covered at once.
那么任何想法?谢谢。
So any idea? Thanks.
推荐答案
每次更改其中一个动画属性时,都需要调用 [dynamicAnimator updateItemUsingCurrentState:item ]
让动态动画师知道你做到了。它会更新它的内部表示以匹配当前状态。
Any time you change one of the animated properties, you need to call [dynamicAnimator updateItemUsingCurrentState:item]
to let the dynamic animator know you did it. It'll update it's internal representation to match the current state.
编辑:我从下面的代码中看到你'重新尝试修改比例。 UIDynamicAnimator
仅支持旋转和位置,而不支持缩放(或任何其他类型的仿射变换)。不幸的是,为了实现只是旋转,它接管转换
。我认为这是 UIDynamicAnimator
中的一个错误(但后来我发现很多UIKit Dynamics的实现被归类为错误)。
I see from your code below that you're trying to modify the scale. UIDynamicAnimator
only supports rotation and position, not scale (or any other type of affine transform). It unfortunately takes over transform
in order to implement just rotation. I consider this a bug in UIDynamicAnimator
(but then I find much of the implementation of UIKit Dynamics to classify as "bugs").
你可以做的是修改你的边界(在调用 updateItem ...
之前)并自己重绘。如果你需要仿射变换的性能,你有几个选择:
What you can do is modify your bounds (before calling updateItem...
) and redraw yourself. If you need the performance of an affine transform, you have a few options:
- 将你的实际绘图逻辑移动到
CALayer
或子视图并修改其比例(更新边界
以匹配,如果您需要碰撞行为仍然有效)。 - 不要将视图附加到行为上,而是附加一个代理对象(只需在
NSObject上实现
)将变换传递给你。然后,您可以将请求的转换与您自己的转换组合。< UIDyanamicItem>
- Move your actual drawing logic into a
CALayer
or subview and modify its scale (updating yourbounds
to match if you need collision behaviors to still work). - Instead of attaching your view to the behavior, attach a proxy object (just implement
<UIDyanamicItem>
on anNSObject
) that passes the transform changes to you. You can then combine the requested transform with your own transform.
这篇关于UIDynamicItem手动更新转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!