我在tableviewController中有一个Textfield,当我将键盘向下拖动时,它就在tabbarController中,它在解散之前就滞后了。我使用的互动模式,所以键盘解散在拖动。
class TempTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.keyboardDismissMode = .interactive
self.clearsSelectionOnViewWillAppear = false
tableView.register(TitleTableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) as! TitleTableViewCell
return cell
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
}
我的tableviewcell有一个uitextfield。然而,当我拖拉键盘时,它会延迟,然后被解职。
class TitleTableViewCell: UITableViewCell {
let titleView: UITextField = {
let textView = UITextField()
textView.text = "Add your title ... "
textView.font = UIFont.preferredFont(forTextStyle: .body)
// textView.sizeToFit()
// textView.isScrollEnabled = false
textView.translatesAutoresizingMaskIntoConstraints=false
return textView
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.contentView.addSubview(titleView)
setTitleViewConstraints()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
func setTitleViewConstraints(){
titleView.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor,constant: 10).isActive=true
titleView.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor,constant: -10).isActive=true
titleView.topAnchor.constraint(equalTo: self.contentView.topAnchor, constant: 10).isActive=true
titleView.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor,constant: -10).isActive=true
}
}
class tabBarViewController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let homeViewController = HomeViewController()
homeViewController.tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "home-tab")?.withRenderingMode(.alwaysOriginal), selectedImage: nil)
let discoverViewController = DiscoverViewController()
discoverViewController.tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "discover-tab")?.withRenderingMode(.alwaysOriginal), selectedImage: nil)
let notificationViewController = NotificationViewController()
notificationViewController.tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "notification-tab")?.withRenderingMode(.alwaysOriginal), selectedImage: nil)
let tempViewController = TempTableViewController()
tempViewController.tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "profile-tab")?.withRenderingMode(.alwaysOriginal), selectedImage: nil)
let tabBarList = [homeViewController, discoverViewController,notificationViewController,tempViewController ]
self.viewControllers = tabBarList.map { viewController in
return UINavigationController(rootViewController: viewController)
}
}
}
这是基于用户凭据选择tabbarController的app委托类。
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var handle: AuthStateDidChangeListenerHandle?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
UINavigationBar.appearance().isOpaque = false
UINavigationBar.appearance().backgroundColor = .white
window = UIWindow(frame: UIScreen.main.bounds)
checkUserStatus()
return true
}
func checkUserStatus(){
window?.backgroundColor = UIColor.white
self.setupRootViewController(viewController: UIViewController())
handle = Auth.auth().addStateDidChangeListener {[weak self] auth,user in
if(user != nil){
self?.setupRootViewController(viewController: tabBarViewController())
}else{
self?.setupRootViewController(viewController: UINavigationController(rootViewController: WelcomeViewController()))
}
}
}
private func setupRootViewController(viewController: UIViewController) {
self.window!.rootViewController = viewController
self.window!.makeKeyAndVisible()
}
https://i.stack.imgur.com/h6uV1.gif
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。