Используя didMoveToWindow, получить ограничение на разрыв - PullRequest
0 голосов
/ 15 марта 2019

Мой inputAccessoryView получает много ограничений на разрыв, когда я переопределяю метод didMoveToWindow

Вот мой код

class ChatInputView: UIView {

        override open func didMoveToWindow() {
            super.didMoveToWindow()
            if #available(iOS 11.0, *) {
                if self.window?.safeAreaLayoutGuide != nil {
                    self.translatesAutoresizingMaskIntoConstraints = false
                    guard let safeArea = self.window?.safeAreaLayoutGuide else {return}
                    let bottom = safeArea.bottomAnchor
                    let constraint = self.bottomAnchor.constraint(lessThanOrEqualToSystemSpacingBelow: bottom, multiplier: 1.0)
                    constraint.isActive = true
                }
            }
        }

    }

И в моем ViewController

lazy var chatBarView: ChatInputView = {
        let view = ChatInputView()
        view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: 50)
        view.backgroundColor = .clear
        return view
    }()

override var inputAccessoryView: UIView? {
        get {
            return chatBarView
        }
    }
override var canBecomeFirstResponder: Bool {
            return true
        }

Вот ограничение разрыва

"<_UISystemBaselineConstraint:0x283320ae0 CCWork_Market.ChatInputView:0x115c081b0.bottom <= UILayoutGuide:0x282e05340'UIViewSafeAreaLayoutGuide'.bottom NSLayoutAnchorConstraintSpace(8)   (active)>",
    "<NSLayoutConstraint:0x283452210 UIInputSetContainerView:0x113e6b800.bottom == UITextEffectsWindow:0x11483c400.bottom   (active)>",
    "<NSLayoutConstraint:0x283408aa0 CCWork_Market.ChatInputView:0x115c081b0.bottom == UIInputSetContainerView:0x113e6b800.bottom   (active)>",
    "<NSLayoutConstraint:0x283452800 'UIViewSafeAreaLayoutGuide-bottom' V:[UILayoutGuide:0x282e05340'UIViewSafeAreaLayoutGuide']-(34)-|   (active, names: '|':UITextEffectsWindow:0x11483c400 )>"
...