Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.fitsBounts and constraint errors #294

Closed
2 tasks
olliekav opened this issue Nov 21, 2019 · 3 comments · Fixed by #519
Closed
2 tasks

.fitsBounts and constraint errors #294

olliekav opened this issue Nov 21, 2019 · 3 comments · Fixed by #519

Comments

@olliekav
Copy link

olliekav commented Nov 21, 2019

Short description

I have a stack view that is the first child view of a view controller that is presented modally, but when I add constraints to the stack view to pin it the view edges (top/bottom/right/left = 0) I get a bunch of constraint errors. This stack view should resize based on half or full views of the panel.

I feel like I'm missing something here?

Steps to reproduce

let recordViewController = storyboard.instantiateViewController(withIdentifier: "RecordViewController") as! RecordViewController
        
        // Initialize floating panel
        floatingPanel = FloatingPanelController()
        floatingPanel.delegate = self
        floatingPanel.contentMode = .fitToBounds
        floatingPanel.set(contentViewController: recordViewController)
        floatingPanel.isRemovalInteractionEnabled = false
        floatingPanel.surfaceView.backgroundColor = .black
        floatingPanel.surfaceView.contentInsets = .init(top: 15, left: 0, bottom: 0, right: 0)

Panel is presented via a button action
self.present(floatingPanel, animated: true, completion:nil)

Constraint errors in the console:

"<NSLayoutConstraint:0x600002ab9b80 UIStackView:0x7fddab8c1de0.top == UILayoutGuide:0x600003097d40'UIViewSafeAreaLayoutGuide'.top   (active)>",
    "<NSLayoutConstraint:0x600002abb3e0 UIStackView:0x7fddab8c1de0.bottom == UILayoutGuide:0x600003097d40'UIViewSafeAreaLayoutGuide'.bottom   (active)>",
    "<NSLayoutConstraint:0x600002ab6850 UIView:0x7fddab8bb440.height == FloatingPanel.FloatingPanelSurfaceView:0x7fdda9e28870.height - 15   (active)>",
    "<NSLayoutConstraint:0x600002ac3ed0 FloatingPanel.FloatingPanelSurfaceView:0x7fdda9e28870.bottom == FloatingPanel.FloatingPanelPassThroughView:0x7fdda9e39760.bottom   (active)>",
    "<NSLayoutConstraint:0x600002adeb20 V:[FloatingPanel.FloatingPanelPassThroughView:0x7fdda9e39760]-(0)-[FloatingPanel.FloatingPanelSurfaceView:0x7fdda9e28870]   (active)>",
    "<NSLayoutConstraint:0x600002abada0 'UIViewSafeAreaLayoutGuide-bottom' V:[UILayoutGuide:0x600003097d40'UIViewSafeAreaLayoutGuide']-(0)-|   (active, names: '|':UIView:0x7fddab8bb440 )>",
    "<NSLayoutConstraint:0x600002ab8820 'UIViewSafeAreaLayoutGuide-top' V:|-(0)-[UILayoutGuide:0x600003097d40'UIViewSafeAreaLayoutGuide']   (active, names: '|':UIView:0x7fddab8bb440 )>"

Screenshot 2019-11-21 at 11 23 39

Environment

v1.7.0

Installation method

  • CocoaPods
  • [x ] Carthage
  • Git submodules

iOS version(s)

13

Xcode version

11.1

@scenee
Copy link
Owner

scenee commented Nov 27, 2019

I guess it's relevant to the distribution mode of your UIStackView because the surface height changes as following a user interaction in the mode as README mentioned.

@olliekav
Copy link
Author

olliekav commented Nov 27, 2019

@scenee Thanks! So after more fiddling with Auto layout and constraints (which seems to be a science in itself), I managed to remove the errors by doing the following:

  • Setting the Stackview top/bottom to priority 999
  • Removing the contentInsets on the panel view
  • Setting the content inset as a top value on the first child view in the stack view

Thanks for the great library btw :)

@GrigoryUlanov
Copy link
Contributor

GrigoryUlanov commented May 26, 2020

@scenee I have the same issue like @olliekav had.

I find out that constraints break when I set contentMode = .fitToBounds, use contentInsets floatingPanel.surfaceView.contentInsets = NOT ZERO and add panel as a child VC (floatingPanelController.addPanel(toParent: parent)).

Steps:

  1. Call: floatingPanelController.addPanel(toParent: parent)
  2. It will call func show(animated: Bool = false, completion: (() -> Void)? = nil) from FloatingPanelController
  3. And here activateLayout() will be called before func move(to: FloatingPanelPosition, animated: Bool, completion: (() -> Void)? = nil)

Here is the problem, because activateLayout() is calling floatingPanel.layoutAdapter.activateLayout(of: floatingPanel.state) which will use default state = hidden and will activate offConstraints with wrong inset.

Hope it will help to resolve this issue.

Thanks a lot for you library!

scenee added a commit that referenced this issue Nov 29, 2021
…nt mode (#519)

They were set to `.required - 1` is #359, which fixed #294. However #294
was an issue on `.fitToBounds` content mode. But because of #444 and #515,
if your panel’s content mode is `.static`, their priorities should be set to
`.required` on `.static` content mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants