我有一个在历史记录中存储用户事件的应用程序。这些事件添加到一个 Controller 上,并显示在不同选项卡内的 Controller 中。
我想添加一个视觉确认,表明当用户点击“保存按钮”时事件已被记录。我正在考虑对界面元素进行动画处理,使其移向负责向用户显示记录的选项卡栏 Controller 。
为了做到这一点,我正在考虑对界面元素之一的中心点进行动画处理。我知道如何为中心点设置动画,但它是沿直线进行的。 如何以更“弯曲”的方式为中心点设置动画?有什么方法可以实现这一点吗?
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/