ios - bar - Pop sobre no apunta sobre el botón
navigation bar ios (3)
Establezca sourceView
y sourceRect
como button
y button.bounds
.
Puede elegir las direcciones de recorrido permitidas según el diseño de su vista.
actionSheet.popoverPresentationController?.sourceView = button
actionSheet.popoverPresentationController?.sourceRect = button.bounds;
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Left;
Si el botón es un objeto BarButton, use este código.
actionSheet.popoverPresentationController?.barButtonItem = button
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Up;
Tengo una aplicación que es compatible con diseños de iPhone y iPad. Para el diseño del iPhone, he creado Action Sheet y Pop over para iPad. El problema es que la flecha emergente no apunta sobre el botón que hice clic. A continuación se muestra mi código ....
let actionSheet = UIAlertController(title: "Choose an option",
message: "Message",
preferredStyle: .ActionSheet)
...
if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad
{
// for iPad
actionSheet.popoverPresentationController?.sourceView = self.view
actionSheet.popoverPresentationController?.sourceRect = self.view.bounds;
actionSheet.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.allZeros;
}
self.presentViewController(actionSheet, animated: true, completion: nil)
Para mí trabajé usando el remitente y el casting como UIView.
alertController.popoverPresentationController?.sourceView = sender as! UIView
alertController.popoverPresentationController?.sourceRect = sender.bounds
alertController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Up
SWIFT 3
Esto funcionó para mí cuando mi botón era un UIBarButtonItem:
if UIDevice.current.userInterfaceIdiom == .pad {
if controller.responds(to: "popoverPresentationController") {
controller.popoverPresentationController?.barButtonItem = YourUIBarButtonName
}
}
Fragmento de código completo a continuación:
func presentActivitySheet() {
let controller = UIActivityViewController(activityItems: [document.fileURL], applicationActivities: nil)
if UIDevice.current.userInterfaceIdiom == .pad {
if controller.responds(to: "popoverPresentationController") {
controller.popoverPresentationController?.barButtonItem = YourUIBarButtonName
}
}
present(controller, animated: true, completion: nil)
}