UIView 动画在 iOS 13 上表现不同

4
以下代码在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一样工作吗?


如果您删除UIViewAnimationOptionAllowAnimatedContent会发生什么? - matt
嗨,你找到解决这个问题的方法了吗?@tsuyoski - Muhammad Fauzi Masykur
2个回答

1

您可以在动画块中像这样更改 self.collectionView.layer.frameself.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];
         }
     }
 }];

0
我是这样解决的。根据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;
         }
     }];
 }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接