具有现有仿射变换的UIKit Dynamics [英] UIKit Dynamics with existing affine transform

查看:127
本文介绍了具有现有仿射变换的UIKit Dynamics的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,有一些缩放转换。当我在它上面应用一些UIKit Dynamics时,它会将它们归零。 /:
如何在视图中跳转时保持视图上的现有转换? :P

I have a view that has some scale transformations. And when I apply some UIKit Dynamics on it, it zeroes them out. /: How can I keep the existing transformation on the view while having it jump around? :P

谢谢。 :)

推荐答案

看看UIDynamicAnimator的 updateItemUsingCurrentState

Take a look at UIDynamicAnimator's updateItemUsingCurrentState.


动态动画师会自动读取您添加到其中的每个动态项目的初始状态(位置和旋转),然后负责更新项目的状态。如果在将动态项目添加到动态动画制作者后主动更改动态项目的状态,请调用此方法以请求动画师阅读并合并新状态。

A dynamic animator automatically reads the initial state (position and rotation) of each dynamic item you add to it, and then takes responsibility for updating the item’s state. If you actively change the state of a dynamic item after you’ve added it to a dynamic animator, call this method to ask the animator to read and incorporate the new state.

因此,在您正在转换的项目添加到动画师之后,只要您更改转换,只需调用 updateItemUsingCurrentState 紧接着。

So anytime you change the transform after the item you're transforming has been added to an animator, just call updateItemUsingCurrentState right after.

id <UIDynamicItem> dynamicItem; // whatever your item is, probably a UIView
UIGravityBehavior *behavior = [[UIGravityBehavior alloc] initWithItems:@[dynamicItem]];
UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; // or however you're getting your animator

[animator addBehavior:behavior];

view.transform = CGAffineTransformMakeScale(1.5, 1.5);
[animator updateItemUsingCurrentState:view];

这篇关于具有现有仿射变换的UIKit Dynamics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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