Извините за большой вопрос, реальный вопрос жирный внизу, теперь некоторое объяснение.
Я использую 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 в пользовательскую точку с пользовательской продолжительностью анимации? Постскриптум Извините за плохой английский.