使用Slack之类的UIViewController滑动UIInputView [英] Slide UIInputView with UIViewController like Slack

查看:121
本文介绍了使用Slack之类的UIViewController滑动UIInputView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样使用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一样做到这一点,

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窗口拍摄快照并将其放置在TableViewControllerNavigationController

All I did was actually taking a snapshot from the inputAccessoryView window and putting it on the NavigationController of the TableViewController

我正在使用 SideMenu "rel =" nofollow noreferrer>乔恩·肯特,使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆