UIToolBar与UICollectionView
问题描述:
我有一个UIToolbar视图,其中有一个UICollectionView。UIToolBar与UICollectionView
工具栏是一个带collectionview的文本视图,collectionview中充满了用户提及。因此,如果在textview中输入“@m”,它将显示与字母“m”匹配的用户名。
它曾经不是工具栏上,但我们意识到它并没有与键盘的互动驳回正确驳回并将其添加到工具栏固定的。 (这将在互动屏幕中间徘徊解雇,也不会消失)
但是现在所有的用户交互不上工作了(尽管它在IB被启用)
这里是工具栏的建立:
override var canBecomeFirstResponder: Bool{
return true
}
override var inputAccessoryView: UIView?{
return self.typingView
}
//里面viewDidLoad中:
let separator = UIView(frame: CGRect(x:0 , y: 0, width: ScreenSize.width(), height: 1))
separator.backgroundColor = UIColor.lightBackgroundGrey
self.typingView.addSubview(separator)
self.typingView.isTranslucent = false
self.typingView.setShadowImage(UIImage(), forToolbarPosition: .any)
self.typingView.setBackgroundImage(UIImage(), forToolbarPosition: .any, barMetrics: .default)
self.typingView.removeFromSuperview()
self.setupMentionableCollectionView() //Sets delegate and data source only
答
既然你创建了IB工具栏,那么你可能有身高限制工具栏和/或collectionView,因此只要collectionView的contentSize发生更改,就应该更新这些值。
我认为,这是怎么回事的是,的CollectionView(这是工具栏的子视图)的框架比在工具栏的框架大,所以这就是为什么你不能点击它。
只是做self.collectionViewHeightConstraint.constant = whatever
和self.typingViewHeightConstraint.constant = whatever + defaultHeight
,并应解决您的问题。
嘿谢谢你,让工具栏的视图始终增加高度以包括集合的高度后,它开始工作。简单! – daredevil1234