2

我有一个将用户事件存储在历史记录中的应用程序。事件被添加到一个控制器上,并显示在不同选项卡内的控制器中。

我想添加一个视觉确认,当用户点击“保存按钮”时,事件已被记录。我正在考虑对界面元素进行动画处理,以向负责向用户显示记录的选项卡栏控制器移动。

动画曲线

为此,我正在考虑为我的一个界面元素的中心点设置动画。我知道如何为中心点设置动画,但它是以直线方式进行的。如何以更“弯曲”的方式为中心点设置动画?有没有办法做到这一点?

CGPoint center = self.ratingReticle.center;

[UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationCurveEaseIn animations:^{
    //move the element offscreen
     self.ratingReticle.center = CGPointMake(260,500);

} completion:^(BOOL finished) {
    //hide the interace element once it is offscreen
    self.ratingReticle.alpha = 0;
    //restore the position of the interface element
    self.ratingReticle.center = center;

    [ UIView animateWithDuration:0.4 animations:^{
        //fade the element back at the original position
        self.ratingReticle.alpha = 1;
    } completion:^(BOOL finished) {

    }];

}];
4

1 回答 1

5

您可以使用 Core Animation 沿贝塞尔曲线移动对象,使用CAKeyFrameAnimation.

-(void)animate
{
  CAKeyframeAnimation *posAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  posAnim.path = [self bezierPath];
  [image.layer addAnimation:posAnim forKey:@"posAnim"];
}

wherebezierPath返回CGPathRef适合您情况的 a 。

于 2012-10-19T19:35:14.260 回答