Last active
August 28, 2018 19:34
-
-
Save uchilaka/ff30360887d5d26634c107b8fa0eda11 to your computer and use it in GitHub Desktop.
Fixing alignment issues with native popup view controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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