无法使用自定义约束创建贴纸浏览器

时间:2016-12-27 14:24:50

标签: ios swift imessage-extension

我用于在 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])
}

enter image description here

但我的故事板看起来像这样:

enter image description here

为什么它没有添加到视图层次结构中?我需要把它放在按钮旁边。按钮是固定的,但贴纸浏览有自己的滚动。怎么做?

1 个答案:

答案 0 :(得分:0)

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

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

   requestPresentationStyle(.expanded)           
}