带有 UICollectionView 的 UIToolBar
UIToolBar with UICollectionView
我有一个 UIToolbar 视图,其中有一个 UICollectionView。
工具栏是一个带有集合视图的文本视图,其中集合视图充满了用户提及。因此,如果在文本视图中键入“@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 中创建了工具栏,因此您可能对工具栏有高度限制 and/or collectionView,因此您应该在 collectionView 的 contentSize 发生变化时更新它们。
我想是因为collectionView(工具栏的子视图)的边框比工具栏的边框大,所以不能点击。
只需执行 self.collectionViewHeightConstraint.constant = whatever
和 self.typingViewHeightConstraint.constant = whatever + defaultHeight
即可解决您的问题。
我有一个 UIToolbar 视图,其中有一个 UICollectionView。
工具栏是一个带有集合视图的文本视图,其中集合视图充满了用户提及。因此,如果在文本视图中键入“@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 中创建了工具栏,因此您可能对工具栏有高度限制 and/or collectionView,因此您应该在 collectionView 的 contentSize 发生变化时更新它们。
我想是因为collectionView(工具栏的子视图)的边框比工具栏的边框大,所以不能点击。
只需执行 self.collectionViewHeightConstraint.constant = whatever
和 self.typingViewHeightConstraint.constant = whatever + defaultHeight
即可解决您的问题。