我在iMessage扩展中用于创建标签浏览器的代码是:

func createStickerBrowser() {

    let controller = MSStickerBrowserViewController(stickerSize: .small)

    view.translatesAutoresizingMaskIntoConstraints = false

    addChildViewController(controller)
    view.addSubview(controller.view)

    controller.stickerBrowserView.dataSource = self
    controller.view.backgroundColor = UIColor.green

    let leading = NSLayoutConstraint(item: controller.view, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 0)
    let trailing = NSLayoutConstraint(item: controller.view, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 0)
    let bottom = NSLayoutConstraint(item: controller.view, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)
    let top = NSLayoutConstraint(item: controller.view, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1, constant: 0)

    view.addConstraints([leading, trailing, top, bottom])
}


ios - 无法创建具有自定义约束的标签浏览器-LMLPHP

但是我的情节提要看起来像这样:

ios - 无法创建具有自定义约束的标签浏览器-LMLPHP

为什么不将其添加到视图层次结构?我需要将其放在按钮旁边。按钮是固定的,但标签浏览具有其自己的滚动。这该怎么做?

最佳答案

放置或替换MSMessagesAppViewController类的viewWIllAppear方法:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

   requestPresentationStyle(.expanded)
}

关于ios - 无法创建具有自定义约束的标签浏览器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41346934/

10-15 15:15