Skip to content

Instantly share code, notes, and snippets.

@uchilaka
Last active August 28, 2018 19:34
Show Gist options
  • Save uchilaka/ff30360887d5d26634c107b8fa0eda11 to your computer and use it in GitHub Desktop.
Save uchilaka/ff30360887d5d26634c107b8fa0eda11 to your computer and use it in GitHub Desktop.
Fixing alignment issues with native popup view controllers
import UIKit
class ViewController: UIViewController {
// Some other code...
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// The next 3 lines of code will apply the fix IF a view controller is being presented as a popup, to align it to the center of the anchor object's view
if let popoverPresentationController = segue.destination.popoverPresentationController, let sourceView = sender as? UIView {
popoverPresentationController.sourceRect = sourceView.bounds;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment