[英]InputAccessoryView covers the bottom bar
知道如何讓inputAccessoryView錨定到標簽欄而不是屏幕底部?
我創建了一個UIViewController並重寫了以下方法:
-(BOOL)canBecomeFirstResponder {
return YES;
}
-(UIView *)inputAccessoryView {
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
self.keyboardInputAccessoryView =[[BRKeyboardInputBarView alloc] initWithFrame:frame leftButtonTitle:@"Left" andRightButtonTitle:@"Send"];
[self.keyboardInputAccessoryView setDelegate:self];
[self.keyboardInputAccessoryView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.keyboardInputAccessoryView removeFromSuperview];
return self.keyboardInputAccessoryView;
}
使用inputAccessoryView查看控制器,覆蓋標簽欄
通過它的外觀,視圖控制器將視圖添加到窗口而不是當前視圖控制器視圖,這將解釋其定位。 但是,如果我刪除該行:
[self.keyboardInputAccessoryView removeFromSuperview];
當我點擊附件視圖的textview時,我遇到了崩潰:
The view hierarchy is not prepared for the constraint:<NSLayoutConstraint:0x7fa0c2ca5f80 BRKeyboardInputBarView:0x7fa0c2d6fad0.bottom == UIInputSetContainerView:0x7fa0c295a2c0.bottom>
所以我想我要問的是添加鍵盤配件視圖的正確方法是什么,以便它可以很好地與自動布局一起使用並避免崩潰,還可以將自身錨定到視圖而不是窗口?
你所看到的是正確的行為。
您看到的結果是因為UIViewController
是一個UIResponder
子類。 通過重寫inputAccessoryView
並返回視圖實例, UIViewController
將負責將該視圖放置在屏幕底部,並在鍵盤出現或消失時對其進行適當的動畫處理。
如果要在鍵盤頂部添加此欄,則需要將textField / inputAccessoryView
的屬性inputAccessoryView
設置為自定義視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.