使用didMoveToWindow获取打破约束

时间:2019-03-15 01:58:37

标签: ios swift uikit constraints nslayoutconstraint

当我重写didMoveToWindow方法时,我的inputAccessoryView得到了很多中断约束

这是我的代码

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

0 个答案:

没有答案