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

Background view wrong frame when inside popover #70

Open
fruitcoder opened this issue May 13, 2016 · 1 comment
Open

Background view wrong frame when inside popover #70

fruitcoder opened this issue May 13, 2016 · 1 comment

Comments

@fruitcoder
Copy link

When I use the sheet inside a popover, the background view has a wrong frame. Looking into viewDidLayoutSubviews, the view of the ImagePickerSheetController is in fact wrong (as is the enclosing popoverView). To fix this I added two lines of code inside viewDidLayoutSubviews:
...
let sheetSize = CGSize(width: view.bounds.width, height: sheetHeight)

    if let _ = popoverPresentationController {
      backgroundView.frame = CGRect(origin: .zero, size: sheetSize)
    }

...

@fruitcoder
Copy link
Author

I actually changed a little more because the arrow color didn't match the background color.

I added a new public property which changes the backgroundColor based on the environment:

public var backgroundColor: UIColor = UIColor(white: 0.0, alpha: 0.3961) {
      didSet {
        if let popoverController = popoverPresentationController {
          popoverController.backgroundColor = backgroundColor
          backgroundView.backgroundColor = .clearColor
        } else {
          backgroundView.backgroundColor = backgroundColor
        }
      }
    }
lazy var backgroundView: UIView = {
    let view = UIView()
    view.accessibilityIdentifier = "ImagePickerSheetBackground"
    view.backgroundColor = self.backgroundColor
    view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ImagePickerSheetController.cancel)))

    return view
}()

In viewDidLayoutSubviews() after sheetSize is calculated

if let controller = popoverPresentationController {
    controller.backgroundColor = backgroundColor
    backgroundView.backgroundColor = .clearColor()
    backgroundView.frame = CGRect(origin: .zero, size: sheetSize)
}

This code might be better of in willMoveToParentViewController or something but this fits my needs

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

No branches or pull requests

1 participant