使用对象的更新位置和倾斜度来移动/旋转对象? [英] Moving/Rotating an object using it's updated position and tilt?

查看:105
本文介绍了使用对象的更新位置和倾斜度来移动/旋转对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这基本上是一个简单的问题,我无法解决...

This is basically a simple issue, which I can't get around ...


  1. 所以,我有一个特定帧的 UIImageView 的对象,通过旋转和平移实现 CAAnimation ,并且它位于新坐标(x,y),并已旋转了一定角度。

  1. So, I have an object of UIImageView of a certain frame over which, I implement CAAnimation with rotation and translation, and it is at new coordinates (x,y), and has been rotated by some degrees.

此动画效果很好。但是,如果我再次从THAT状态进行旋转和移动,我希望对象在旋转之后使用STEP 1中的新框架和新属性,然后再次旋转新角度。

This animation works beautifully. But if I again do a rotation and movement from THAT state, I want the object to use the new frame and new properties from STEP 1 after its rotation and again rotate by the new angle.

到目前为止,当我再次尝试旋转时,它会使用其标准状态&帧大小(在初始化过程中)并对其进行旋转...

As of now, when I try rotation again, it uses its standard state & frame size(during initialization) and performs rotation on it...

这就是说...如果我有一个正方形的帧(100、200、10、10),然后将其旋转45度,现在形状是一个不同的正方形,与原始正方形相比具有不同的帧大小和端点,并且我执行了新的旋转(例如)152度,它需要在较新的正方形上旋转...但是事实证明,它使用与上一个相同的帧大小(x,y,10,10)。

如何继续旋转/移动具有更新位置和状态的对象?

How can I continue rotating / moving the object with its updated position and state ??

注意: (如果您需要查看动画代码)

此是我的动画代码,涉及简单的旋转和移动! http://pastebin.com/cR8zrKRq

This is the code for my animation, which involves simple rotation and movement ! http://pastebin.com/cR8zrKRq

推荐答案

您需要保存旋转步骤并在animationDidStop:方法中更新对象旋转。因此,在您的cas中,您应该应用:

You need to save the rotation step and update object rotation in animationDidStop: method. So, in your cas, you should apply:

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{ 
   //angle is global
   CATransform3D rotationTransform = CATransform3DMakeRotation((angle%4)*M_PI_4, 0, 0, 1);
   [object.layer setTransform:rotationTransform];
   object.center = tempFrame; //already there
}

其中angle是动画(步)的整数计数器,值0、1、2、3。我的步骤是M_PI_4。解决这个问题的方法可能更好,但这应该可以解决问题

where angle is an integer counter of animations(steps) with values 0,1,2,3. My step is M_PI_4. There is probably a better solution to the problem, but this should do the trick

这篇关于使用对象的更新位置和倾斜度来移动/旋转对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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