【问题标题】:Moving/Rotating an object using it's updated position and tilt?使用更新的位置和倾斜度移动/旋转对象?
【发布时间】:2011-12-29 13:56:44
【问题描述】:

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

    1234563一些度数。
  1. 这个动画效果很好。但是,如果我再次从那个状态进行旋转和移动,我希望对象在旋转后使用 STEP 1 中的新框架和新属性,并再次旋转新角度。

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

And by this I mean... If I have a square of frame (100, 200, 10, 10), and I rotate it by 45 degrees, the shape is now a different square, with different frame size and end points compared to the original square, and I implement a new rotation by (say) 152 degrees on it and it needs to perform a rotation on the newer square... But it turns out that it uses the same frame size as the previous one (x,y, 10, 10).

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


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

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

【问题讨论】:

    标签: iphone objective-c cocoa-touch core-animation core-graphics


    【解决方案1】:

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

    -(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
    }
    

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

    【讨论】:

    • 明白了!!史诗般的答案:)
    • @Micheal:你有机会聊聊吗?如果您能消除一些疑问,那就太棒了...
    猜你喜欢
    • 2012-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    相关资源
    最近更新 更多