gpt4 book ai didi

ios - 如何在 iOS 8+ 的 iPhone 上以编程方式配置和显示弹出窗口

转载 作者:可可西里 更新时间:2023-11-01 03:36:40 27 4
gpt4 key购买 nike

如何在 iOS 8 中仅使用 Objective-C 代码,不使用 Story Boards 或其他 Interface Builder 工件,在 iPhone(所有尺寸和方向)的弹出窗口中呈现 UIViewController。

最佳答案

在 iOS 8 中,您可以将任何 View Controller 配置为显示为弹出窗口,如下所示:

UIViewController* controller = ...; // your initialization goes here

// set modal presentation style to popover on your view controller
// must be done before you reference controller.popoverPresentationController
controller.modalPresentationStyle = UIModalPresentationPopover;
controller.preferredContentSize = CGSizeMake(150, 300);

// configure popover style & delegate
UIPopoverPresentationController *popover = controller.popoverPresentationController;
popover.delegate = controller;
popover.sourceView = sourceView;
popover.sourceRect = CGRectMake(150,300,1,1);
popover.permittedArrowDirections = UIPopoverArrowDirectionAny;

// display the controller in the usual way
[self presentViewController:controller animated:YES completion:nil];

为了让它在 iPhone 上显示为弹出窗口,请将其添加到弹出窗口(您在上面设置的)的 UIPopoverPresentationControllerDelegate 委托(delegate)中:

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

关于ios - 如何在 iOS 8+ 的 iPhone 上以编程方式配置和显示弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31236389/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com