0

I need to create a rotation animation for a uiimageview. The best analogy I can think of is a picture hanging on a wall. The nail that holds up the picture is placed at the top of the picture.

If I pushed the picture I want to model the slight swinging motion of the picture back and forth until it eventually reverts back its its starting position.

I know I'll first have to start by changing the view's anchor point but I'm unsure how to approach the rest of the problem. I could use CABasicAnimation but I'm guessing that would be ridiculously complex/overkill to get a relatively simple animation.

Any suggestions?

[EDIT]

This answer actually worked for me nicely using blocks :)

4

1 回答 1

3

我认为使用CABasicAnimation动画transform.rotation属性和选择正确的计时功能应该不会太难。类似于以下内容:

    CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    [anim setToValue:[NSNumber numberWithFloat:startAngle]];
    [anim setFromValue:[NSNumber numberWithDouble:endAngle]];
    [anim setDuration:duration];
    [anim setRepeatCount:count];
    [anim setAutoreverses:YES];
    [anim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [selectedCoverView.layer addAnimation:anim forKey:@"SwingingRotation"];

关键是选择合适的计时功能;+ (id)functionWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y如果预定义的都没有问题,您可以使用(其中控制点定义贝塞尔曲线)定义任意时间函数。

于 2012-04-25T10:51:09.327 回答