Set the direction and position of the UIPopover arrow manually

I am using UIBarButtonItem. In my script, I want to show a popover from each button when I double-click this button. Therefore, I use UITapGesture from this UIBarButtonItem. But the popover arrow always appears in the middle of the whole UIBarButtonItem.

I cannot make an arrow in the middle of each button. My friend told me to indicate the direction of the arrow using a dot, but I do not know how to do this.

How to set both the position and direction of the moving arrow?

+5
source share
4 answers

Set the direction for popover using:

[yourPopover setPopoverArrowDirection: UIPopoverArrowDirectionDown];

UIPopoverArrowDirectionUp, UIPopoverArrowDirectionLeft UIPopoverArrowDirectionRight, UIPopoverArrowDirectionAny.

+8

allowedArrowDirections =.Down, . Swift:

if let popoverPresentationController = shareViewController.popoverPresentationController {
    popoverPresentationController.permittedArrowDirections = .Down
    popoverPresentationController.delegate = self
    popoverPresentationController.sourceView = sender as! UIButton
    popoverPresentationController.sourceRect = CGRectMake(0, 0, sender.frame.size.width, sender.frame.size.height)
}
+12

IBAction, (id)sender . (.. ). . , . . UIPopoverController.

-(IBAction)sortButtonPressed:(id)sender {
  // Set up your popover class, this varies per your implementation
  MyPopoverClass *iPop = [[MyPopoverClass alloc] initWithNibName:@"MyPopover" bundle:nil];
  UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:iPop];

  // Grab the button info from the input parameter
  UIButton *button = (UIButton *)sender;
  CGRect buttonRectangle = button.frame;

  // Set the arrow direction
  UIPopoverDirection dir = UIPopoverArrowDirectionAny; // Or Up, Down, etc.

  // Put it all together
  [popover presentPopoverFromRect:buttonRectangle inView:mySubView permittedArrowDirections:dir animated:YES];

  [popover release]
  [iPop release];
}

, CGRect . / .

0

You can set the arrow direction in the Storyboard Segue attribute inspector. For example, I set the down arrow only in the following screenshot:

0
source

All Articles