Could not create sticker browser with custom constraints

77 views Asked by At

The code I use to create sticker browser in iMessage extension is:

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

but my Storyboard looks like this:

enter image description here

Why it is not added to the view hierarchy? I need to place it next to button. Button is fixed, but sticker browse has its own scroll. How to do this?

1

There are 1 answers

0
Dilip Bhuva On

Put or replace viewWIllAppear method of MSMessagesAppViewController class:

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

   requestPresentationStyle(.expanded)           
}