我正在使用以下代码在toolBarButtonItem上显示UIAlertController:
使用此代码显示的alertController出现在右侧而不是居中。我希望alertController能够恰好位于toolBarButtonItem上方的中心位置。
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.sourceRect
和alertController.popoverPresentationController.sourceView
代替barbutton。 - Bhumit Mehta