-
-
Save ravanar-sk/14abd753ac95e833a8b83917eb9ef02d to your computer and use it in GitHub Desktop.
Revisions
-
susanstevens revised this gist
Feb 11, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ ### How to Create a Popover on iPhone #### Storyboard set up -
susanstevens revised this gist
Feb 11, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ ### How to Create a Popover on iPhone (iOS 13) #### Storyboard set up Add your view controllers in storyboard. In the Size Inspector, change the simulated size of the popover view controller to "Freeform". This doesn't change the popover's size when you run the app, but it does make it easier to lay out subviews correctly. -
susanstevens revised this gist
Feb 11, 2020 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,8 @@ Add your view controllers in storyboard. In the Size Inspector, change the simul When adding the segue between view controllers, select "Present as Popover". <img width="600" alt="segue" src="https://user-images.githubusercontent.com/10423328/74289839-0409c080-4d28-11ea-80a3-e5411bef139a.png"> #### Code In your view controller, override the `prepare(for:sender:)` method so that you can access the popover view controller just before it appears on screen. @@ -47,3 +49,6 @@ extension ViewController: UIPopoverPresentationControllerDelegate { 1. Access the popover's `popoverPresentationController`. This is the object that manages the presentation of the popover. 2. Set your view controller as the popover presentation controller's delegate. 3. Implement the `adaptivePresentationStyle` method to tell the popover presentation controller how to adapt to different size classes. In this case, you don't want the popover's presentation to change, so you return `.none`.  -
susanstevens revised this gist
Feb 11, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,8 @@ Add your view controllers in storyboard. In the Size Inspector, change the simulated size of the popover view controller to "Freeform". This doesn't change the popover's size when you run the app, but it does make it easier to lay out subviews correctly. <img width="600" alt="storyboard" src="https://user-images.githubusercontent.com/10423328/74289665-952c6780-4d27-11ea-8769-356853568d85.png"> When adding the segue between view controllers, select "Present as Popover". #### Code -
susanstevens created this gist
Feb 11, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #### Storyboard set up Add your view controllers in storyboard. In the Size Inspector, change the simulated size of the popover view controller to "Freeform". This doesn't change the popover's size when you run the app, but it does make it easier to lay out subviews correctly. When adding the segue between view controllers, select "Present as Popover". #### Code In your view controller, override the `prepare(for:sender:)` method so that you can access the popover view controller just before it appears on screen. Start by setting the `preferredContentSize`. ```swift class ViewController: UIViewController { override func prepare(for segue: UIStoryboardSegue, sender: Any?) { segue.destination.preferredContentSize = CGSize(width: 300, height: 200) } } ``` At this point, if you run your app on an iPhone simulator, you'll notice that the popover view controller still covers most of the screen. By default, popovers display as full-screen when the horizontal size class is compact. To fix this, add the following code: ```swift class ViewController: UIViewController { override func prepare(for segue: UIStoryboardSegue, sender: Any?) { segue.destination.preferredContentSize = CGSize(width: 300, height: 200) if let presentationController = segue.destination.popoverPresentationController { // 1 presentationController.delegate = self // 2 } } } extension ViewController: UIPopoverPresentationControllerDelegate { func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle { return .none // 3 } } ``` 1. Access the popover's `popoverPresentationController`. This is the object that manages the presentation of the popover. 2. Set your view controller as the popover presentation controller's delegate. 3. Implement the `adaptivePresentationStyle` method to tell the popover presentation controller how to adapt to different size classes. In this case, you don't want the popover's presentation to change, so you return `.none`.