手动设置UIPopover箭头方向和位置

R. *_*ewi 8 objective-c uibarbuttonitem uipopovercontroller ios

我正在使用UIBarButtonItem.在我的场景中,我想在双击该栏按钮时显示每个栏按钮的弹出窗口.所以我使用UIBarButtonItem中的UITapGesture.但是,弹出箭头始终出现在所有UIBarButtonItem的中间.

我无法使箭头出现在每个条形按钮的中间.我的朋友告诉我用点设置箭头方向,但我不知道该怎么做.

如何设置弹出箭头的位置和方向?

Evg*_*rev 14

我使用方法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)
}
Run Code Online (Sandbox Code Playgroud)

  • 你可以使用`popController.popoverPresentationController?.sourceView = sender作为?UIView; popController.popoverPresentationController?.sourceRect = sender.bounds` (2认同)
  • 你可以通过`popoverPresentationController.sourceRect = sender.bounds`改变`popoverPresentationController.sourceRect = CGRectMake(0, 0, sender.frame.size.width, sender.frame.size.height)` (2认同)

Sam*_*hie 10

使用以下方法设置弹出窗口的方向:

[yourPopover setPopoverArrowDirection: UIPopoverArrowDirectionDown];
Run Code Online (Sandbox Code Playgroud)

你也可以使用UIPopoverArrowDirectionUp,UIPopoverArrowDirectionLeftUIPopoverArrowDirectionRightUIPopoverArrowDirectionAny.

对于斯威夫特

    yourPopover?.permittedArrowDirections = .up or .down or .left or .right
Run Code Online (Sandbox Code Playgroud)