jjzjj

ios - UIPopoverPresentationController 不调用 UIAdaptivePresentationControllerDelegate 方法

coder 2024-01-18 原文

我尝试通过 UIPopoverPresentationController 在 iPad 上呈现弹出窗口。一切都很好,但似乎没有调用 UIAdaptivePresentationControllerDelegate 的方法。

AddRewardController *addRewardVC = [[AddRewardController alloc] initWithNibName:@"AddRewardController" bundle:nil];
addRewardVC.modalPresentationStyle = UIModalPresentationPopover;
addRewardVC.preferredContentSize = CGSizeMake(500, 255);

UIPopoverPresentationController *popVC = addRewardVC.popoverPresentationController;
popVC.delegate = self;
popVC.sourceView = self.view;;
popVC.sourceRect = CGRectMake(self.view.center.x, self.view.center.y, 1.0f, 1.0f); // present in center of view
popVC.permittedArrowDirections = 0; //I dont want to show arrow so i set it to 0

[self presentViewController:addRewardVC animated:YES completion:nil];

我的 View Controller 实现了 UIAdaptivePresentationControllerDelegateUIPopoverPresentationControllerDelegate

我像这样实现 UIAdaptivePresentationControllerDelegate 委托(delegate)(但没有一个被调用)

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
    return UIModalPresentationFullScreen;
}

- (UIViewController *)presentationController:(UIPresentationController *)controller viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style {
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller.presentedViewController];
    return navController;
}

我是不是做错了什么,为什么它不调用我的委托(delegate)方法?

最佳答案

使用这个委托(delegate)方法:-

(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection;

您正在实现的方法仅适用于 iPhone。

关于ios - UIPopoverPresentationController 不调用 UIAdaptivePresentationControllerDelegate 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33431907/

有关ios - UIPopoverPresentationController 不调用 UIAdaptivePresentationControllerDelegate 方法的更多相关文章

随机推荐