【问题标题】:UIView animateWithDuration behaves differently on iOS 13UIView animateWithDuration 在 iOS 13 上的行为不同
【发布时间】:2020-02-05 08:21:59
【问题描述】:

以下代码在 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 会怎样?
  • 嗨,您找到解决此问题的方法了吗? @tsuyoski

标签: ios objective-c uiviewanimation ios13


【解决方案1】:

我通过以下方式解决了这个问题。只是根据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;
         }
     }];
 }

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-17
      • 2015-03-29
      • 2023-04-04
      • 2019-11-16
      • 1970-01-01
      • 1970-01-01
      • 2015-01-07
      • 2012-01-13
      相关资源
      最近更新 更多