UITabBar Transition Issue Below iOS 11 Swift

前端 未结 1 1100
逝去的感伤
逝去的感伤 2021-01-26 14:22

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 an

相关标签:
1条回答
  • 2021-01-26 14:37

    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

    0 讨论(0)
提交回复
热议问题