BarButtonItem 上显示的 UIAlertController 未正确居中

UIAlertController shown on BarButtonItem not centered properly

我正在使用以下代码在 toolBarButtonItem 上显示 UIAlertController,

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

    [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    }]];     

    [alertController addAction:[UIAlertAction actionWithTitle:@"Delete Selected Accounts" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
        [Utility showAlertWithTitle:nil message:DELETE_ACCOUNT delegate:self tag:1 buttons:@[@"Cancel", @"Delete"]];
    }]];
    alertController.popoverPresentationController.barButtonItem = self.moreButtonItem;
    [self presentViewController:alertController animated:YES completion:nil];

使用此代码显示的 alertController 显示在右侧而不是居中。我希望 alertController 恰好出现在 toolBarButtonItem 的中心位置。

尝试添加以下代码

 alertController.popoverPresentationController.sourceView = senderView; //your view
 alertController.popoverPresentationController.sourceRect = senderView.bounds; //your view
 alertController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;

这解决了我的问题。