Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 10 Messages Extension - Wrong Layout when using Storyboard Segue

When using Segues in Messages Extension Application the layout gets messed up.
Is there any way to solve this issue while still using storrybord segues?

Screenshots:
(Note: The first and second View / ViewController are identical. The segue-type doesn't matter)

Expanded Presentation Style:

1Exp 2Exp


Compact Presentation Style:

1Comp 2Comp

Update 1:

The top and bottom layout guides reset after a segue

  • compact:
    • top: should be: 0 but is: 20
    • bottom: should be: 44 but is: 0
  • expanded:
    • top: should be: 86 but is: 20
    • bottom: should be: 44 but is: 0


P.S. Can someone create a new "messages-extension" tag?

like image 221
123FLO321 Avatar asked Jul 26 '16 14:07

123FLO321


1 Answers

I hope this won't always be necessary, but I ended up using a combination of a constraint outlet, presentationStyle variable, and viewDidLayoutSubviews() to overcome this bug/oversight.

In my DetailViewController:

@IBOutlet weak var myViewTopConstraint: NSLayoutConstraint!
var presentationStyle: MSMessagesAppPresentationStyle?

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    if presentationStyle == .expanded {
        myViewTopConstraint.constant = 86
    } else {
        myViewTopConstraint.constant = 0
    }
}

And in my MainViewController:

override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
    if let detailController = presentedViewController as? DetailViewController {
        detailController.presentationStyle = presentationStyle
    }
}

And in case it makes a difference, my segue presents modally as a Page Sheet.

like image 179
Zig Avatar answered Nov 20 '22 09:11

Zig