iphone - UITableView setContentInset 大值动画缓慢

标签 iphone ios cocoa-touch uitableview uiscrollview

我有一个 TableView ,其中另一个 View (称为 bottomView)作为 subview 放置在 TableView 内容的底部。我想要发生的是,当用户在 tableview 的最底部拉起时,在释放时我想向上滑动 tableview 以便出现 bottomView 。为此,我实现了委托(delegate):

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate: (BOOL)decelerate {
    [UIView animateWithDuration:0.1 animations:^{
        [self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 250, 0)];
    }];
}
动画 block 中的

(250是bottomView的高度)。我期望发生的情况是 tableview 向上滑动 250pts,露出 bottomView。奇怪的是,最终发生的情况是,表格只向上滑动了一点点(可能是 100 点),而且速度非常缓慢,大约需要 5 秒,而我的动画 block 只有 0.1 秒。

有人知道为什么会发生这种情况吗?

谢谢

最佳答案

试试这个,希望有帮助


  -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
   {
        aTableView.contentInset = UIEdgeInsetsMake(0, 0, 250, 0);
   }
   -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
   {
        UIEdgeInsets insects =  aTableView.contentInset;
        if(insects.top == 0)
         {
            aTableView.contentInset = UIEdgeInsetsMake(0, 0, 250, 0);
            CGSize size = aTableView.contentSize;
            int height = size.height;
             [UIView animateWithDuration:0.2 animations:^{
                 aTableView.contentOffset = CGPointMake(0, height-250);
             }];
             aTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
         }

   }

  -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  {
      if(!decelerate)
       {
          UIEdgeInsets insects =  aTableView.contentInset;
         if(insects.top == 0)
         {
           CGSize size = aTableView.contentSize;
           int height = size.height;
              [UIView animateWithDuration:0.1 animations:^{
           aTableView.contentOffset = CGPointMake(0, height-250);
              }];
           aTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
         }
      }
  }


根据需求调整contentOffset

关于iphone - UITableView setContentInset 大值动画缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17799459/

相关文章:

ios - 根据 NSDictionay 中的键对 NSDictionary 的 NSArray 进行分组

objective-c - 尝试使用 2 个 UIButtons 创建 View 时出现错误

iphone - TTNavigator popViewController?

iphone - 如何阻止音频文件在 Apple 的 MixerHost 核心音频示例中循环播放

ios - Apple开发者帐户续订-设备未重置

ios - 在我使用 forin collectionView.visibleCells 将 cell.selected 设置为 NO 后,选择其他它们再次自动选择

ios - iOS:处理nsstring

iphone - 如何以编程方式将应用程序带到前台

iOS 成员(member)中心 : Standard development provisioning profile vs Enterprise development provisioning profile

objective-c - UINavigationBar topItem/items 似乎在后面双弹出