我需要使Pipe普遍流行,调整其规模,使其达到所提出的观点。 因此,我设立了一个主计长子级,处理所有列报逻辑:
class PopoverViewController: UIViewController, UIPopoverPresentationControllerDelegate {
var contentView = UIView()
init(contentView: UIView, sourceView: UIView) {
super.init(nibName: nil, bundle: nil)
self.contentView = contentView
view = contentView
preferredContentSize = view.bounds.size
modalPresentationStyle = .popover
guard let controller = popoverPresentationController else {return}
controller.permittedArrowDirections = .up
controller.delegate = self
controller.sourceView = sourceView
controller.sourceRect = sourceView.bounds
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension PopoverViewController: UIAdaptivePresentationControllerDelegate {
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}
}
它的规模和一切都受到罚款,然后我确定一个特定框架(如320x260等)的倾向。
But when I set it to a presented controller s view frame or bounds size, popover presents with default size:
我试图检查内容。 以印刷方式得出的观点,即零宽度和高度。 内容 观点陈述守则:
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .white
addSubview(titleLabel)
addSubview(contentLabel)
titleLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(appearance.xlSpace)
make.leading.trailing.equalToSuperview().inset(appearance.xlSpace)
}
contentLabel.snp.makeConstraints { make in
make.top.equalTo(titleLabel.snp.bottom).offset(appearance.lSpace)
make.leading.trailing.equalToSuperview().inset(appearance.sSpace)
make.bottom.equalToSuperview().inset(appearance.xsSpace)
}
print("width: (self.bounds.width), height: (self.bounds.height)")
}
介绍守则:
func showInfo() {
let view = PopupView()
let controller = PopoverViewController(contentView: view, sourceView: contentView.infoButton)
present(controller, animated: true, completion: nil)
}
我怎么能够适当安排我的人为控制员,让他更愿意考虑范围大小和作出选择。 普遍提出任何已变成控制者的观点?