In the previous speech we looked at a demo, using modal, but in fact, if you want to consider the iphone and ipad devices, the default modal will be filled with the screen, and PopOver can occupy only a small piece of the screen, Before we talked about using PopOver in the iphone, it looked the same as modal. In fact, PopOver has a lot of settings in the iphone is also in effect. Modify the demo in the previous session.
First in order to highlight the effect we put the background color of the first scene deepened, orange OK, and then modify the scene one button click to scene two transition way, now we choose PopOver.
Note the attribute viewer for PopOver:
Anchor (anchor point) indicates where the small arrows on our popover are pointing, because the segue is triggered by a button, so the anchor point defaults to the button itself.
Then continue setting in your code.
In the Prepareforsegue method, add:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if"EditSegue"{ ifletas? ModalViewController{ iflet ppc = vc.popoverPresentationController{ //popover方式跳转才会起作用 } vc.nameToEdit = name.text } } }}
You can call the Popoverpresentationcontoller method of the Segue's target controller, which only has a return value when Segue is PopOver, so you can set it in parentheses for popover with an optional binding. Now the iphone is running when scene two will fill the entire screen, see below, if we want to set a translucent effect, that is, the way of alert, you can use the following method:
First set the PopOver delegate:
class ViewController: UIViewController,UIPopoverPresentationControllerDelegate
ppc.delegateself
To implement the delegate method:
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!, traitCollection: UITraitCollection!) -> UIModalPresentationStyle { return UIModalPresentationStyle.OverFullScreen }
The default is fullscreen, now switch to Overfullscreen now run to see if it is transparent and can see the back:
The problem now is that the "Finish" button is missing, and now the "finish" is turned back because the direct popover to the scene II without navigating the controller.
Now you need to implement another delegate method:
func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? { return UINavigationController(rootViewController: controller.presentedViewController) }
At least now the navigation controller appears:
Now our scene two is like a transparent glass, now I want to achieve is the frosted glass effect, this need to set blur, modify the previous delegate method:
func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? { let navcon = UINavigationController(rootViewController: controller.presentedViewController) .ExtraLight)) visualEffectView.frame = navcon.view.bounds navcon.view.insertSubview0) return navcon }
Effect
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"We all love Paul Hegarty" Stanford IOS8 public class personal note Popover Segue