ios UIView动画曲线

时间:2012-06-11 19:50:31

标签: uiviewanimation uiviewanimation-curve

有没有办法像下面这样简单易行的方式做事?曲线似乎仍然使用EaseOut

[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView animateWithDuration:0.5 animations:^{
    // ... do stuff here
}];

3 个答案:

答案 0 :(得分:29)

你正在混合两种不同的UIView动画。你应该使用以下任何一种:

[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseIn
                 animations:^{
                    // ... do stuff here
               } completion:NULL];

这来自较新的基于块的UIView动画API。另一方面,第一行是旧的UIView动画API的一部分,如下所示:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
// ... do stuff here
[UIView commitAnimations];

他们做同样的事情你也可以使用(虽然Apple建议使用基于块的API,因为在动画结束后回调更简单/更清晰。)

答案 1 :(得分:2)

您可以使用Core Animation,CAKeyFrameAnimation来定义曲线点。请参阅本教程:http://nachbaur.com/blog/core-animation-part-4

答案 2 :(得分:0)

让我们取曲线点p1,p2,p3,p4和p5,&找到每对相邻点的中点。将m1标记为p1和p2的中点。同样适用于m2,m3,m4。

  • 将四边形曲线添加到点m2,以p2作为控制点。
  • 将四边形曲线添加到m3点,以p3作为控制点。
  • 将四边形曲线添加到点m4,以p4作为控制点。

代码:

CGFloat screenHeight = self.view.frame.size.height;
CGFloat screenWidth = self.view.frame.size.width;

UIView *aniView = [[UIView alloc] initWithFrame:CGRectMake(50, screenHeight, 50, 50)];
[aniView setBackgroundColor:[UIColor redColor]];
aniView.layer.cornerRadius = 25.0;
[self.view addSubview:aniView];


UIBezierPath *movePath = [UIBezierPath bezierPath];
[movePath moveToPoint:aniView.center];
[movePath addQuadCurveToPoint:CGPointMake(screenWidth-50,screenHeight-50)
                 controlPoint:CGPointMake(screenWidth/2,screenHeight-150)];
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;
moveAnim.removedOnCompletion = YES;
CAAnimationGroup *animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:moveAnim,  nil];
animGroup.duration = 2.0;

[CATransaction begin]; {
    [CATransaction setCompletionBlock:^{
        [aniView.layer removeAllAnimations];
        [aniView removeFromSuperview];
    }];

    [aniView.layer addAnimation:animGroup forKey:nil];

} [CATransaction commit];

将上面的代码复制到某个方法中并尝试调用方法...