沿二次曲线设置视图的中心点

时间:2012-10-19 19:27:21

标签: objective-c ios cocoa-touch animation uiview

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

我想添加一个视觉确认信息,当用户点击"保存按钮"时已记录事件。我正在考虑动画一个界面元素,以便向标签栏控制器移动,该控制器负责向用户显示记录。

Animation curve

为了做到这一点,我想到了动画我的一个界面元素的中心点。我知道如何设置中心点的动画,但它是直线的。 如何在更多"曲线"中为中心点设置动画。方式?有没有办法实现这个目标?

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) {

    }];

}];

1 个答案:

答案 0 :(得分:5)

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

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

bezierPath返回适合您情况的CGPathRef