Forked from smileyborg/InteractiveTransitionCollectionViewDeselection.m
Created
December 21, 2017 22:55
-
-
Save rlaguilar/3580534621ed7d3b261341df556f381d to your computer and use it in GitHub Desktop.
Animate table view deselection alongside interactive transition on iOS 11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
In iOS 11, interactive view controller transitions no longer scrub by setting the layer speed to zero | |
and changing the timeOffset. As a result of this change, implicit animations that occur in places like | |
-viewWillAppear: (called during an interactive transition) no longer end up “caught in” the animation. | |
To get the same behavior for table view row deselection as before, you can either use UITableViewController | |
which implements this for you, or you can implement it manually by deselecting the row in an alongside | |
animation for the transition (set up in -viewWillAppear: using the transition coordinator). | |
Here is an example implementation which correctly handles some of the more subtle corner cases: | |
*/ | |
- (void)viewWillAppear:(BOOL)animated { | |
[super viewWillAppear:animated]; | |
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow]; | |
if (selectedIndexPath != nil) { | |
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator; | |
if (coordinator != nil) { | |
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { | |
[self.tableView deselectRowAtIndexPath:selectedIndexPath animated:YES]; | |
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) { | |
if (context.cancelled) { | |
[self.tableView selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; | |
} | |
}]; | |
} else { | |
[self.tableView deselectRowAtIndexPath:selectedIndexPath animated:animated]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment