63

Is it possible to present a popover without any sort of arrows pointing somewhere?

David Liu
  • 9,426
  • 5
  • 40
  • 63
  • 1
    So you want a modal view controller? – kennytm Aug 04 '10 at 07:38
  • 2
    Are you're suggesting that I use `-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 Aug 04 '10 at 18:42

17 Answers17

111

Yes it is possible just do:

 [self.popoverController presentPopoverFromBarButtonItem:anItem   
                                permittedArrowDirections:0
                                                animated:YES];

The zero represent no direction.

Matt
  • 2,803
  • 9
  • 33
  • 57
  • it works for me!!! thanks.. will apple accept this? ... by the way, is it posible to present a keyboard inside a popover, the way it looks on ipad passcode? http://stackoverflow.com/questions/3636560/how-to-present-keyboard-inside-popover-ipad-passcode-lock-style – Omer Sep 03 '10 at 14:10
  • Setting this parameter to 0 breaks the sizing of my popover. – devios1 Aug 08 '13 at 20:12
  • 2
    Try creating subclass of UIPopoverBackground class and override arrowDirection getter method. In that method return 0. – NetDeveloper Aug 23 '13 at 14:58
  • For swift use UIPopoverArrowDirection.allZeros – Jbryson Mar 17 '15 at 19:13
  • 5
    this is not working for iOS 9. there is no allZeros property. Xcode did autocorrect that to just using (). so UIPopoverArrowDirection() works on iOS 9 – ryanmmanalo Sep 30 '15 at 20:09
26

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
}
Sachin Agarwal
  • 579
  • 10
  • 9
19

Swift4:

popover.permittedArrowDirections = []              
bphi
  • 3,115
  • 3
  • 23
  • 36
11

Set the permittedArrowDirections to 0.

permittedArrowDirections:0

Code -

[self.popoverController presentPopoverFromBarButtonItem:anItem   
                                permittedArrowDirections:0
                                                animated:YES];

Zero tells "NoDirection".

Akshay
  • 2,973
  • 6
  • 43
  • 75
9

Swift3, this code work for me

popover.permittedArrowDirections = .init(rawValue: 0)
Twitter khuong291
  • 11,328
  • 15
  • 80
  • 116
5

For Swift 2.0 and iOS9 the solution is:

popoverViewController?.permittedArrowDirections = UIPopoverArrowDirection()
NSNoob
  • 5,548
  • 6
  • 41
  • 54
Nuno Vieira
  • 193
  • 2
  • 10
5

In swift 3, you can build a UIPopoverArrowDirection extension for this:

extension UIPopoverArrowDirection {
    public static var noArrow: UIPopoverArrowDirection {
        return UIPopoverArrowDirection(rawValue: 0)
    }
}

and the you can do:

popoverPresentationController!.permittedArrowDirections = .noArrow
manueGE
  • 1,169
  • 11
  • 14
5

In Swift, you can simply do:

popoverPresentationController.permittedArrowDirections = []

Since in another configuration you could have used:

popoverPresentationController.permittedArrowDirections = [.up, .down]
Tomn
  • 198
  • 1
  • 4
4

Try this , it works for me.

[self.popoverViewController presentPopoverFromRect:rect inView:self.view  permittedArrowDirections:0 animated:YES];
suresh
  • 41
  • 1
3

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);
AJPerez
  • 3,435
  • 10
  • 61
  • 91
Asim Khan
  • 508
  • 1
  • 7
  • 21
2

This works fine for me.

[popoverController presentPopoverFromRect:CGRectMake(0, 0, 20, 20)
                                    inView:self.view 
                  permittedArrowDirections:NULL 
                                  animated:YES];

Enjoy Coding.

Kundan
  • 3,084
  • 2
  • 28
  • 65
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:^{

}];
fedtuck
  • 4,154
  • 3
  • 13
  • 3
2

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.

Kevlar
  • 8,804
  • 9
  • 55
  • 81
  • 2
    Unfortunately, presentModalViewController is limited to certain particular frame sizes, while popovers are not, unless I'm missing something. They also don't provide the same look and feel as a popover. – David Liu Aug 09 '10 at 19:55
  • That's correct. Unfortunately, if your requirements are strict you may have to roll your own popups to get what you want. – Kevlar Aug 09 '10 at 22:53
1

Try this one

[popOverController presentPopoverFromRect:CGRectMake(0, 0, 30, 40) inView:popOverContentView permittedArrowDirections:0 animated:NO];
MouzmiSadiq
  • 2,069
  • 3
  • 18
  • 21
1

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

GxocT
  • 764
  • 1
  • 10
  • 20
0

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()
Sujay U N
  • 4,974
  • 11
  • 52
  • 88
-3

A simple solution in SWIFT:

popover!.permittedArrowDirections = nil
Blank
  • 4,872
  • 2
  • 28
  • 25