Reputation: 644
The following code was working successfully till iOS12.2, which was sliding up the calendar grid until it's hidden.
-(void) hideCalendarGrid {
[UIView animateWithDuration:10.0 delay:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{ //iwashere animation wrong iOS13. duration set to 10.0 for testing originally it was 0.2
CGRect collectionViewRect = self.collectionView.frame;
collectionViewRect.origin.y -= collectionViewRect.size.height;
self.collectionView.frame = collectionViewRect;
CGRect tableViewRect = self.tableView.frame;
tableViewRect.origin.y -= collectionViewRect.size.height;
tableViewRect.size.height += collectionViewRect.size.height;
self.tableView.frame = tableViewRect;
} completion:^(BOOL finished){
if (finished) {
// Reset frame but make it invisible
self.collectionView.hidden = YES;
self.collectionView.frame = self.collectionViewRectWhenVisible;
self.collectionViewHeightConstraint.constant = 0.0f;
self.isCalendarOn = NO;
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isCalendarOn"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self configureNavigationBar];
self.backButton.enabled = YES;
self.backButton.hidden = NO;
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"doneTutorial3.0CalendarGrid"]) {
[self showHowToHideCalendarGridTutorial];
}
}
}];
}
Demo on iOS 12.2 (works as expected) https://youtu.be/sU5rbnujh3U
Demo on iOS 13 (not the way I want) https://youtu.be/mk3AFsh5FCw
Does anyone know how to make the animation work like iOS12 on iOS13?
Upvotes: 4
Views: 345
Reputation: 644
I solved this the following way. Just changing the timing of setting table height depending on iOS version.
-(void) hideCalendarGrid {
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
CGRect collectionViewRect = self.collectionView.frame;
self.collectionViewRectTemp = self.collectionView.frame;
collectionViewRect.origin.y -= collectionViewRect.size.height;
self.collectionView.frame = collectionViewRect;
if (@available(iOS 13.0, *)) {
// iOS 13 DO NOT CHANGE TABLE HEIGHT YET
CGRect tableViewRect = self.tableView.frame;
tableViewRect.origin.y -= collectionViewRect.size.height;
self.tableView.frame = tableViewRect;
} else {
// iOS 12 and earlier CHANGE TABLE Y AND HEIGHT
CGRect tableViewRect = self.tableView.frame;
tableViewRect.origin.y -= collectionViewRect.size.height;
tableViewRect.size.height += collectionViewRect.size.height;
self.tableView.frame = tableViewRect;
}
} completion:^(BOOL finished){
if (finished) {
if (@available(iOS 13.0, *)) {
// iOS 13 CHANGE TABLE HEIGHT NOW
CGRect tableViewRect = self.tableView.frame;
tableViewRect.size.height += self.collectionViewRectTemp.size.height;
self.tableView.frame = tableViewRect;
}
// Reset frame but make it invisible
self.collectionView.hidden = YES;
self.collectionView.frame = self.collectionViewRectWhenVisible;
self.collectionViewHeightConstraint.constant = 0.0f;
self.isCalendarOn = NO;
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isCalendarOn"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self configureNavigationBar];
self.backButton.enabled = YES;
self.backButton.hidden = NO;
}
}];
}
Upvotes: 0
Reputation: 71
You can change self.collectionView.layer.frame and self.tableView.layer.frame in animations block also like this:
self.collectionView.layer.frame = collectionViewRect;
self.tableView.layer.frame = tableViewRect;
so your code maybe like this:
-(void) hideCalendarGrid {
[UIView animateWithDuration:10.0 delay:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{ //iwashere animation wrong iOS13. duration set to 10.0 for testing originally it was 0.2
CGRect collectionViewRect = self.collectionView.frame;
collectionViewRect.origin.y -= collectionViewRect.size.height;
self.collectionView.frame = collectionViewRect;
// code for iOS 13
self.collectionView.layer.frame = collectionViewRect;
CGRect tableViewRect = self.tableView.frame;
tableViewRect.origin.y -= collectionViewRect.size.height;
tableViewRect.size.height += collectionViewRect.size.height;
self.tableView.frame = tableViewRect;
// code for iOS 13
self.tableView.layer.frame = tableViewRect;
} completion:^(BOOL finished){
if (finished) {
// Reset frame but make it invisible
self.collectionView.hidden = YES;
self.collectionView.frame = self.collectionViewRectWhenVisible;
self.collectionViewHeightConstraint.constant = 0.0f;
self.isCalendarOn = NO;
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isCalendarOn"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self configureNavigationBar];
self.backButton.enabled = YES;
self.backButton.hidden = NO;
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"doneTutorial3.0CalendarGrid"]) {
[self showHowToHideCalendarGridTutorial];
}
}
}];
Upvotes: 1