English 中文(简体)
presented presented presented presented
原标题:Set popover size to the size of presented controller s view
  • 时间:2020-04-24 09:05:33
  •  标签:
  • ios
  • swift

我需要使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等)的倾向。

“entergraph

But when I set it to a presented controller s view frame or bounds size, popover presents with default size:

“enterography

我试图检查内容。 以印刷方式得出的观点,即零宽度和高度。 内容 观点陈述守则:

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

我怎么能够适当安排我的人为控制员,让他更愿意考虑范围大小和作出选择。 普遍提出任何已变成控制者的观点?

问题回答

我认为,问题是,你过早地设定了<代码>,编号为。 Try do it in viewWillAppear. 当被点名时,我不认为已经妥善确定和阐明一切。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签