Is it possible to present a popover without any sort of arrows pointing somewhere?
17 Answers
For iPhone and swift 2.0 try this one
Code to initiate popover
initiatePopover(){
let popoverContent = self.storyboard?.instantiateViewControllerWithIdentifier("XYZController") as! XYZController
let nav = UINavigationController(rootViewController: popoverContent)
nav.modalPresentationStyle = UIModalPresentationStyle.Popover
let popover = nav.popoverPresentationController
popoverContent.preferredContentSize = CGSizeMake(250 ,200)
popover!.delegate = self
popover!.sourceView = self.view
popover!.sourceRect = CGRectMake(200,200,0,0)
popover!.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
self.presentViewController(nav, animated: true, completion: nil)
}
And add this to your ViewController
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.None
}
In my case for swift developers
popoverController.sourceView = self.view
popoverController.sourceRect = self.view.bounds
popoverController.backgroundColor = UIColor.brownColor()
popoverController.permittedArrowDirections = UIPopoverArrowDirection.init(rawValue: 0)
popoverController.sourceRect = CGRectMake(width/4, hieght/4, width/2, hieght/2);
Do not use Popovers if you don't want to show arrows. Present your view controller as a Modal and use a UIModalPresentationFormSheet instead.
Example:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MyStoryBoard" bundle:nil];
UIViewController* viewController = [sb instantiateViewControllerWithIdentifier:@"myViewController"];
viewController.modalPresentationStyle = UIModalPresentationFormSheet;
[presenterViewController presentViewController: viewController animated:YES completion:^{
}];
Nope, there is no UIPopoverArrowDirectionNone
option, and UIPopoverArrowDirectionUnknown
throws an exception i think if you try to use that to present.
Instead of a popover controller, you can call presentModalViewController:animated:
and set the controller you are presenting to have a modal presentation style of UIModalPresentationFormSheet
or perhaps UIModalPresentationPageSheet
. Those are more traditional popup screens than popovers are.
I use popover to show menu depending on touch coordinate. In this case popover uses maximum height of self.view
CGRect popeverFrame = CGRectMake(touchPoint.x, touchPoint.y, 0, 0);
[self.popover presentPopoverFromRect:popeverFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
But when I use 0-direction. Popover rectangle doesn't set it height to maximum and can only be set by appropriate property.
CGRect popeverFrame = CGRectMake(touchPoint.x, touchPoint.y, 0, 0);
[self.popover presentPopoverFromRect:popeverFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
Hope this will help: Help with UIPopOverController size
To make a pop over direction none and make it to appear in center of the view controller :
let PopSrnVar = popoverPresentationController
let ConRctVar = view.frame
PopSrnVar!.sourceRect = CGRectMake(ConRctVar.width/4, ConRctVar.height/4, ConRctVar.width/2, ConRctVar.height/2)
// To make arrows as none
PopSrnVar!.permittedArrowDirections = UIPopoverArrowDirection()
-presentModalViewController:animated:
? That's extremely different from a UIPopover. It doesn't provide the same look and feel as a UIPopover, and you're limited to certain fixed dimensions. – David Liu