objective-c - 沿二次曲线对 View 的中心点进行动画处理

标签 objective-c ios cocoa-touch animation uiview

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

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

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

    }];

}];

最佳答案

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

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

其中 bezierPath 返回适合您情况的 CGPathRef

关于objective-c - 沿二次曲线对 View 的中心点进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12981127/

相关文章:

objective-c - 如何解决仍然为零的委托(delegate)

ios - UIPickerView 忽略约束

ios - 在 objective-c 中编译基于 firebase 的项目时出错

当我尝试运行 6 时,iOS 模拟器恢复到 iOS7

ios - UIBarButtonItem 色调颜色不起作用

ios - 如何在 Objective C 中获取枚举的数值,或用数值设置枚举?

ios - 如何让 SwiftUI 动态响应用户事件?

ios - Facebook 登录不断返回 Nil - Parse/Swift

iphone - 如何为 iOS 应用程序创建自定义错误域?

iphone - 如何在我没有子类化的 UITabBarController 上隐藏 UITabBar?