Reputation: 861
I have a UITableView, and when it stops scrolling (scrollViewDidEndDecelerating:) the height of the current cell expands by setting the variable currentRow and reloading:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
CGFloat current_offset = self.tableView.contentOffset.y;
currentRow = [self.tableView indexPathForRowAtPoint:CGPointMake(0, current_offset)].row;
[self.tableView beginUpdates];
[self.tableView endUpdates];
};
The animation works fine, but it temporarily prevents the tableview from being scrollable/interactive. So if I touch the screen while the cell is expanding, I end up not being able to scroll unless I try again.
Is there a workaround or another way to achieve the same effect?
Upvotes: 6
Views: 1098
Reputation: 598
Try this:
[CATransaction begin];
[self.tableView beginUpdates];
[CATransaction setCompletionBlock: ^{
// Code to be executed upon completion
CGFloat current_offset = self.tableView.contentOffset.y;
currentRow = [self.tableView indexPathForRowAtPoint:CGPointMake(0, current_offset)].row;
}];
[self.tableView endUpdates];
[CATransaction commit];
Lastly you might want to commit animations also for the tableview
Upvotes: 1
Reputation: 40502
The UITableView animation system is completely opaque. There is no API that let's you modify or override what happens beyond selecting what type of animation occurs for inserts/deletes. Peruse the header file and look at the stack traces.
So, there is no practical way to prevent UITableView
animations from blocking touches, nor should you want to. Doing so could lead to manipulating a dequeued cell. So, unless you are fond of EXC_BAD_ACCESS
errors, don't do that.
Note that that user interactions are disabled for all UITableView
animations, not just updates -- inserts, deletes, and reloads are handled the same way.
It seems like a reasonable hook to have into UITableView
animations, though, so be sure to submit a bug report to Apple and maybe we'll see it in a future enhancement.
Upvotes: 1
Reputation: 8954
You can use this method, to stop animations,
but I'm not sure that it will not make problems.
- (void)stopAnimations { for (UITableViewCell *cell in [self.tableView visibleCells]) { [cell.layer removeAllAnimations]; } }
Try adding this on your TableViewController
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self stopAnimations]; }
or try to add tap gesture recognizer to Application's window and then call stopAinimations on gesture trigger.
Upvotes: 4
Reputation: 1897
It is not possible to interrupt tableview animation also it is not advisable. If you want the tableview to be responsible on first touch you can use reloadData
method instead of beginUpdates
else try using reloadSection
method. It may help but preventing the animation is not good idea.
Upvotes: 1
Reputation: 10938
If you are using iOS 7+ you could try calling the table updates inside a [UIView performWithoutAnimation:]
block.
Upvotes: 1