如何解决UIModalPresentationPopover 在 iOS 14.5 中错误地显示全屏的问题
我从 2018 年开始更新一个应用程序,该应用程序使用 UIModalPresentationPopover 来呈现一个以小视图而非全屏显示的弹出窗口。未更改的代码适用于 iPhone 6(iOS 12.5)和 iPhone 8(iOS 14.5)(模拟器)。在 iPhone 11 (iOS 14.5)(设备和模拟器)上,popover 显示全屏而不是小视图。如果我从使用相同代码的 AppStore 下载旧应用程序,则弹出窗口在 iPhone 11 (iOS 14.5) 上运行良好。我尝试过的任何方法都无法解决 iPhone 11 上的全屏问题。
附上完整代码。谢谢
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
// Insures that iPhone popovers look like iPad popovers
return UIModalPresentationNone;
}
- (IBAction)cogButtonHandler:(UIButton *)sender {
UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
}
else {
storyboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
}
GM_CogButtonViewController *cogTVC = [storyboard instantiateViewControllerWithIdentifier:@"GM_CogButtonViewController_InAppID"];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
cogTVC.preferredContentSize = CGSizeMake(130,65);
}
else {
cogTVC.preferredContentSize = CGSizeMake(170,170);
}
cogTVC.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *presentationController = [cogTVC popoverPresentationController];
presentationController.backgroundColor = cogTVC.view.backgroundColor;
presentationController.permittedArrowDirections = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) ? UIPopoverArrowDirectionLeft : UIPopoverArrowDirectionAny;
presentationController.sourceView = _cogButton.superview; // Not self.view!
presentationController.sourceRect = _cogButton.frame;
// The order of presentation of the next two lines are critical
// See http://stackoverflow.com/questions/38750913/ios-9-presenting-popover-takes-full-screen
presentationController.delegate = self;
[self presentViewController:cogTVC animated:YES completion:nil];
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。