UIBarButtonItem上显示的UIAlertController未正确居中

3
我正在使用以下代码在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上方的中心位置。

1
尝试使用alertController.popoverPresentationController.sourceRectalertController.popoverPresentationController.sourceView代替barbutton。 - Bhumit Mehta
1个回答

1

尝试添加以下代码:

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

这解决了我的问题。

非常感谢您的帮助。 - Nikhil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接