以下代码在iOS12.2之前一直可以成功运行,iOS12.2将日历网格向上滑动直到隐藏为止。

 -(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];
             }
         }
     }];
 }

在iOS 12.2上的演示(按预期工作)
https://youtu.be/sU5rbnujh3U

在iOS 13上进行演示(不是我想要的方式)
https://youtu.be/mk3AFsh5FCw

有谁知道如何使动画像iOS13上的iOS12一样工作?

最佳答案

您还可以在动画块中更改 self.collectionView.layer.frame self.tableView.layer.frame ,如下所示:

self.collectionView.layer.frame = collectionViewRect;

self.tableView.layer.frame = tableViewRect;

,因此您的代码可能像这样:

-(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];
         }
     }
 }];

关于ios - UIView animateWithDuration在iOS 13上的行为有所不同,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58279708/

10-13 06:14