简体   繁体   中英

UITabBar Transition Issue Below iOS 11 Swift

I got this transition issue with iOS 9, I've attached a GIF below.

It looks like the custom textView is presuming x-axis of the tab bar top before segue and then settling to its original position.

However there's no issue with iOS 11, but same with iOS 10.

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).

I'm using Auto-layout. The comment textView is pinned to buttom of superView . Any tip would be highly appreciated.

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
    }
}

在此处输入图片说明

Try another solution.

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

EDIT IPHONE X SUPPORT

lazy var viewAcc: SafeAreaInputAccessoryViewWrapperView = {
    return SafeAreaInputAccessoryViewWrapperView(for: button)
}()

Hope it is helpful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM