本文介绍了iOS 11 Swift下的UITabBar过渡问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在iOS 9中遇到了这个转换问题,我在下面添加了一个GIF。I got this transition issue with iOS 9, I've attached a GIF below.它看起来像自定义 textView 假定在segue之前标签栏顶部的x轴,然后稳定到其原始位置。 It looks like the custom textView is presuming x-axis of the tab bar top before segue and then settling to its original position. 然而,iOS 11没有问题,但与iOS 10相同。However there's no issue with iOS 11, but same with iOS 10.我也怀疑这可能是由推送 segue引起的,因为它与其他类型的segue(没有任何高度稳定故障)转换得很好。 I also suspect this might be caused by the push segue, since it transitions fine with the other kinds of segue (without any height settling glitch). 我正在使用自动布局。注释 textView 固定为 superView 的底部。任何小费都将受到高度赞赏。 I'm using Auto-layout. The comment textView is pinned to buttom of superView. Any tip would be highly appreciated. 这是在推送时解雇 UITabBar 的代码。Here's the code that's dismissing UITabBar on push.override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "previewVC" { let destinationController = segue.destination as! PostViewController destinationController.hidesBottomBarWhenPushed = true }} 推荐答案尝试其他解决方案。 使用您的文本作为 UIViewController 的输入附件视图,因此从故事板中删除该底部视图Use Your text as input accessory view of UIViewController so remove that bottom view from storyboard在视图控制器中添加以下内容Add Following in your view controller var viewAcc: UIView?var sendButton: UIButton!var inputTextField: UITextField!override var inputAccessoryView: UIView? { return viewAcc}override var canBecomeFirstResponder: Bool { return true}在视图中加载方法添加以下代码 注意:请根据您的要求更改约束In View Did load method add following code Note:Please change constraints according to your requirement viewAcc = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44)) viewAcc?.backgroundColor = UIColor.white inputTextField = UITextField (frame: CGRect(x:8, y:0, width:UIScreen.main.bounds.width, height: 44 )) inputTextField.inputAccessoryView = nil inputTextField.delegate = self as? UITextFieldDelegate inputTextField.placeholder = "Enter message..." viewAcc?.backgroundColor = .white viewAcc?.addSubview(inputTextField); let topBorderView = UIView() topBorderView.backgroundColor = UIColor(white: 0.5, alpha: 0.5) viewAcc?.addSubview(topBorderView) viewAcc?.addConstraintsWithFormat(format: "H:|[v0]|", views: topBorderView) viewAcc?.addConstraintsWithFormat(format: "V:|[v0(0.5)]", views: topBorderView) sendButton = UIButton(type: .system) sendButton.isEnabled = true sendButton.titleLabel?.font = UIFont.systemFont(ofSize: 16) sendButton.setTitle("Send", for: .normal) sendButton.contentEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8) sendButton.addTarget(self, action: #selector(handleSend), for: .touchUpInside) viewAcc?.addSubview(sendButton) inputTextField.translatesAutoresizingMaskIntoConstraints = false sendButton.translatesAutoresizingMaskIntoConstraints = false viewAcc?.addConstraint(NSLayoutConstraint(item: inputTextField, attribute: .left, relatedBy: .equal, toItem: viewAcc, attribute: .left, multiplier: 1, constant: 8)) viewAcc?.addConstraint(NSLayoutConstraint(item: inputTextField, attribute: .top, relatedBy: .equal, toItem: viewAcc, attribute: .top, multiplier: 1, constant: 7.5)) viewAcc?.addConstraint(NSLayoutConstraint(item: inputTextField, attribute: .right, relatedBy: .equal, toItem: sendButton, attribute: .left, multiplier: 1, constant: -2)) viewAcc?.addConstraint(NSLayoutConstraint(item: inputTextField, attribute: .bottom, relatedBy: .equal, toItem: viewAcc, attribute: .bottom, multiplier: 1, constant: -8)) viewAcc?.addConstraint(NSLayoutConstraint(item: sendButton, attribute: .right, relatedBy: .equal, toItem: viewAcc, attribute: .right, multiplier: 1, constant: 0)) viewAcc?.addConstraint(NSLayoutConstraint(item: sendButton, attribute: .bottom, relatedBy: .equal, toItem: viewAcc, attribute: .bottom, multiplier: 1, constant: -4.5))由于您的文字视图不是视图控制器的子视图,因此它将按预期工作As your text view is not subview of view controller so it will work as expected 编辑IPHONE X支持 lazy var viewAcc: SafeAreaInputAccessoryViewWrapperView = { return SafeAreaInputAccessoryViewWrapperView(for: button)}()希望有帮助 这篇关于iOS 11 Swift下的UITabBar过渡问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-19 03:24