使用Slack之类的UIViewController滑动UIInputView [英] Slide UIInputView with UIViewController like Slack
问题描述
我想这样使用UIViewController的输入附件视图:
I'd like to use the UIViewController's input accessory view like this:
override func canBecomeFirstResponder() -> Bool {
return true
}
override var inputAccessoryView: UIView! {
return self.bar
}
但是问题是我有一个类似抽屉的视图,并且当我将视图滑动到打开状态时,输入视图仍停留在窗口上.如何像Slack一样将输入视图保持在中心视图上.
but the issue is that I have a drawer like view and when I slide the view open, the input view stays on the window. How can I keep the input view on the center view like Slack does it.
我的输入视图位于底部,占据了整个屏幕(红色是下图中的输入视图):
Where my input view stays at the bottom, taking up the full screen (the red is the input view in the image below):
推荐答案
完全有两种方法可以像Slack一样做到这一点,详细信息的贴纸:在iOS中实现粘性输入字段,以显示他如何做到这一点,实际上他将空的UIView
用作inputAccessoryView
然后在屏幕上跟踪它的坐标以知道将其自定义视图与空视图相关联的位置,如果您要在iPad上支持SplitViewController
,这种方法可能会有所帮助,但是如果您对此不感兴趣,则可以看看我如何设法像这张图片一样
There are two ways to do this exactly like Slack doing it, Meiwin has a medium post here A Stickler for Details: Implementing Sticky Input Field in iOS to show how he managed to do this which he actually puts an empty UIView
as an inputAccessoryView
then track it’s coordinates on screen to know where to put his custom view in relation with the empty view, this way can be helpful if you are going to support SplitViewController
on iPad, but if you are not interested in this way, you can see how I managed to do this like this image
这里是刷卡之前
在这里
我实际上所做的只是从inputAccessoryView
窗口拍摄快照并将其放置在TableViewController
的NavigationController
上
All I did was actually taking a snapshot from the inputAccessoryView
window and putting it on the NavigationController
of the TableViewController
我正在使用UISideMenuNavigationControllerDelegate
I am using SideMenu from Jon Kent and it’s pretty easy to do it with the UISideMenuNavigationControllerDelegate
var isInputAccessoryViewEnabled = true {
didSet {
self.inputAccessoryView?.isHidden = !self.isInputAccessoryViewEnabled
if self.isInputAccessoryViewEnabled {self.becomeFirstResponder()}
}
}
func sideMenuWillAppear(menu: UISideMenuNavigationController, animated: Bool) {
let inputWindow = UIApplication.shared.windows.filter({$0.className == "UITextEffectsWindow"}).first
self.inputAccessoryViewSnapShot = inputWindow?.snapshotView(afterScreenUpdates: false)
if let snapShotView = self.inputAccessoryViewSnapShot, let navView = self.navigationController?.view {
navView.addSubview(snapShotView)
}
self.isInputAccessoryViewEnabled = false
}
func sideMenuDidDisappear(menu: UISideMenuNavigationController, animated: Bool) {
self.inputAccessoryViewSnapShot?.removeFromSuperview()
self.isInputAccessoryViewEnabled = true
}
我希望能有所帮助:)
这篇关于使用Slack之类的UIViewController滑动UIInputView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!