2017-08-14 37 views
0

我有一個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 

回答

1

既然你創建了IB工具欄,那麼你可能有身高限制工具欄和/或collectionView,因此只要collectionView的contentSize發生更改,就應該更新這些值。

我認爲,這是怎麼回事的是,的CollectionView(這是工具欄的子視圖)的框架比在工具欄的框架大,所以這就是爲什麼你不能點擊它。

只是做self.collectionViewHeightConstraint.constant = whateverself.typingViewHeightConstraint.constant = whatever + defaultHeight,並應解決您的問題。

+0

嘿謝謝你,讓工具欄的視圖始終增加高度以包括集合的高度後,它開始工作。簡單! – daredevil1234