简体   繁体   English

UIView animateWithDuration 在 iOS 13 上的行为不同

[英]UIView animateWithDuration behaves differently on iOS 13

The following code was working successfully till iOS12.2, which was sliding up the calendar grid until it's hidden.以下代码一直成功运行到 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];
             }
         }
     }];
 }

Demo on iOS 12.2 (works as expected) https://youtu.be/sU5rbnujh3U iOS 12.2 上的演示(按预期工作) https://youtu.be/sU5rbnujh3U

Demo on iOS 13 (not the way I want) https://youtu.be/mk3AFsh5FCw iOS 13 上的演示(不是我想要的方式) https://youtu.be/mk3AFsh5FCw

Does anyone know how to make the animation work like iOS12 on iOS13?有谁知道如何使 animation 在 iOS13 上像 iOS12 一样工作?

You can change self.collectionView.layer.frame and self.tableView.layer.frame in animations block also like this:您也可以像这样在动画块中更改self.collectionView.layer.frameself.tableView.layer.frame

self.collectionView.layer.frame = collectionViewRect; self.collectionView.layer.frame = collectionViewRect;

self.tableView.layer.frame = tableViewRect; 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];
         }
     }
 }];

I solved this the following way.我通过以下方式解决了这个问题。 Just changing the timing of setting table height depending on iOS version.只需根据 iOS 版本更改设置表高度的时间。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM