问题描述
我有一个带有单个按钮的 InputAccessoryView。但是,我得到以下输出。
我已经在我的 InputAccessoryView
中设置了我的 ViewController
,如下所示;
lazy var customInputView: ButtonInputView = {
let frame = CGRect(x: 0,y: 0,width: view.frame.width,height: 50)
let view = ButtonInputView(frame: frame)
view.doneButton.addTarget(self,action: #selector(signIn),for: .touchUpInside)
return view
}()
override var inputAccessoryView: UIView? {
return customInputView
}
Xcode 打破了在我的视图框架中设置的 50 的高度限制。有什么原因吗??
自定义配件输入视图类
class ButtonInputView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setUpView()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
lazy var doneButton: UIButton = {
let view = UIButton()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = Color.accent
view.setTitle("Done",for: .normal)
view.titleLabel?.font = Font.mainButton
view.layer.cornerRadius = 19
return view
}()
let separator: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .opaqueSeparator
return view
}()
private func setUpView() {
backgroundColor = Color.background
addSubview(doneButton)
addSubview(separator)
let separatorHeight = (1 / (UIScreen.main.scale))
if let titleLabelText = doneButton.titleLabel?.text {
doneButton.widthAnchor.constraint(equalToConstant: titleLabelText.width(usingFont: Font.mainButton) + 32).isActive = true
}
NSLayoutConstraint.activate([
separator.topAnchor.constraint(equalTo: topAnchor),separator.leadingAnchor.constraint(equalTo: leadingAnchor),separator.trailingAnchor.constraint(equalTo: trailingAnchor),separator.heightAnchor.constraint(equalToConstant: separatorHeight),doneButton.topAnchor.constraint(equalTo: separator.bottomAnchor,constant: 6),doneButton.trailingAnchor.constraint(equalTo: trailingAnchor,constant: -16),doneButton.bottomAnchor.constraint(equalTo: bottomAnchor,constant: -6),])
}
override var intrinsicContentSize: CGSize {
return CGSize.zero
}
override func didMovetoWindow() {
super.didMovetoWindow()
if #available(iOS 11.0,*) {
if let window = window {
bottomAnchor.constraint(lessthanorEqualToSystemSpacingBelow: window.safeAreaLayoutGuide.bottomAnchor,multiplier: 1.0).isActive = true
}
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)