Sorry for a big question, real question are bold in bottom, now some explanation.
I'm use CoreAnimation in my project for animate some objects moving like this.
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"];
And now I need to animate scrolling of some UIScrollView. I can't use setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
method, because it can't customise animation duration.
I can make it like this
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];
but it's not CoreAnimation, and using 2 different kinds of animation techniques in one app is not a good practice, I think.
Is there a way to use a CoreAnimation to animate scrolling of UIScrollView content to custom point with custom animation duration? P.S. Sorry for the bad English.
You could use:
[UIView animateWithDuration:duration animations:^ {
[scrollView setContentOffset:destination animated:NO];
}];
You can set the duration of the animation this way.
[UIScrollViewNameHere setContentOffset:CGPointMake(x value of where you want to move to, y value of where you want to move to) animated:YES];
for example:
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(4, 2, 2341, 412)];
[scroll setContentOffset:CGPointMake(320, 0) animated:YES];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With