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 attempt was to throw the animating code (setContentOffset) in a separate method and calling it using:
[self performSelectorOnMainThread:@selector(scrollMethod:) withObject:sender waitUntilDone:YES];
The problem is that the method returns immediately, not after the animation is finished, even though waitUntilDone is YES, but apparently that is how animation works.
I know that I can use thread waiting but it is not clean, so I will only use it as a last resort. (Maybe I would use this if I know the time it takes the scrolling animation to happen.)
Any ideas on how to go about this are welcome.
(P.S. The scenario is this: I am showing a popover, which is displayed perfectly when there is no keyboard, however, if the keyboard is visible, the popover's height shrinks which sometimes reduces it to almost border only. So just before showing the popover, I want to scroll the view upwards so that the popover never pops in the keyboard.)
UITableView inherits setContentOffset:animated: from its superclass, UIScrollView. Check out the scrollViewDidEndScrollingAnimation: method of UIScrollViewDelegate.
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.
}
}];
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