collectionView scrollToItemAtIndexPath不向下滚动最初键盘可见时

时间:2015-07-19 02:08:05

标签: ios swift uicollectionview scrollview

希望有人可以帮助我解决这个令人沮丧的行为。

我的UICollectionView scrollToItemAtIndexPath在所有情况下均可正常工作,除非键盘可见且内容大小小于约780像素的高度值。在内容大小超出此范围之后,滚动按原样工作,并且在键盘被隐藏时始终如此。

我的整个collectionView以及其他视图都嵌入在scrollView中。

keyboardWillShow方法包含以下内容:

        UIView.animateWithDuration(animationDuration, animations: { () -> Void in
            self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, intersectionOfKeyboardRectAndWindowRect.size.height, 0)
            self.collectionView.contentInset = UIEdgeInsetsMake(intersectionOfKeyboardRectAndWindowRect.size.height, 0, 0, 0)
            self.scrollView.scrollRectToVisible(self.messageView.frame, animated: false)
        })

如果删除定义collectionView偏移量的第二行,则底部的行为正常,但collectionView的顶部隐藏在顶部栏下。

我试图提供Modally并且问题仍然存在。我滚动collectionView的方法是:

 private func updateCollectionView() {
     collectionView.reloadData()
     if self.messages.count > 0 {

         let indexPath = NSIndexPath(forItem: self.messages.count - 1, inSection: 0)
         self.collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: false)
     }
 }

看起来好像集合视图的高度以某种方式设置为忽略AutoLayout约束的大数字,并且只有当内容大小超过该值时滚动才会变为活动状态。

0 个答案:

没有答案