非常抱歉我的问题比较冗长,实际问题在底部用粗体标出,现在简要解释一下。
我在项目中使用CoreAnimation来实现对象的移动动画,就像这样。
CABasicAnimation *moveAnimation;
moveAnimation=[CABasicAnimation animationWithKeyPath:@"position"];
moveAnimation.duration = 2.0;
moveAnimation.repeatCount=1;
moveAnimation.autoreverses=NO;
moveAnimation.delegate = self;
moveAnimation.fromValue = [NSValue valueWithCGPoint:[crawler.layer position]];
moveAnimation.fillMode = kCAFillModeForwards;
moveAnimation.removedOnCompletion = NO;
CGPoint p;
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
[crawler.layer addAnimation:moveAnimation forKey:@"moveAnimation"];
现在我需要对某个UIScrollView进行滚动动画。我不能使用setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
方法,因为它无法自定义动画持续时间。
我可以像这样实现:
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x + 200, scrollView.contentOffset.y);
[UIView commitAnimations];
但这并不是CoreAnimation,而且在一个应用程序中使用两种不同的动画技术并不是一个好的实践,我认为。
有没有一种方法可以使用CoreAnimation来动画滚动UIScrollView内容到自定义点,并指定自定义动画持续时间? P.S. 抱歉我的英语不好。