So I have this line of code:
[tableView setContentOffset:point animated:YES];
and I want to run another piece of code after the animation ends. My a
For a scrollView, tableView or collectionView if you do something like this:
[self.collectionView setContentOffset:CGPointMake(self.collectionView.contentOffset.x+260.0,
self.collectionView.contentOffset.y)
animated:YES];
then you'll get back a:
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
when the scroll finishes.
You do NOT get this callback if the user moves the view.
Try to use this method:
[UIView animateWithDuration:0.6f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
// Do your animations here.
}
completion:^(BOOL finished){
if (finished) {
// Do your method here after your animation.
}
}];
You can create animations and tell them directly to perform a block after they're done.
Here's an alternative that may play nicer with the UITableView's animations.
[UIView beginAnimations:nil context:sender];
[UIView setDelegate:self];
[UIView setDidStopSelector:@selector(scrollMethod:)];
[tableView setContentOffset:point];
[UIView commitAnimations];
And make sure to implement your scrollMethod:
with this signature:
- (void)scrollMethod:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
You can use the context to know which sender
you have. Read the UIView docs for more on UIView animations.
UITableView inherits setContentOffset:animated: from its superclass, UIScrollView. Check out the scrollViewDidEndScrollingAnimation: method of UIScrollViewDelegate.