如何在故事板中创建弹出窗口 - iOS

时间:2014-12-11 13:16:01

标签: ios iphone xcode popup storyboard

我正在使用故事板创建iPhone应用程序。在这里,如何在storyboard上创建弹出窗口以及如何在viewcontroller上添加和关闭此弹出窗口。

弹出示例图片:

enter image description here

我想在这样的故事板中添加弹出窗口:

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以像这样创建它(不要忘记将<UIPopoverControllerDelegate>添加到呈现视图控制器类)

UIStoryboard* storyboard = [UIStoryboard storyboardWithName : @"MainStoryboard" bundle : nil];
    MyCustomPopoverContentVC* customContentViewController = [storyboard instantiateViewControllerWithIdentifier : @"MyCustomPopoverContentVC"];

// initialize popover controller with content view controller
UIPopoverController* popoverController = [[UIPopoverController alloc] initWithContentViewController: anyCustomViewController];
popoverController.delegate = self;
// change popoverContentSize here
CGRect contentFrame = CGRectMake(0.0, 0, 500.0, 500.0);
popoverController.popoverContentSize = contentFrame.size;
// present popover controller
[popoverController presentPopoverFromRect: _buttonRectForPopoverController inView: self.view permittedArrowDirections: UIPopoverArrowDirectionUp animated: YES];

和你的展示视图控制器类中的其他地方一个例子`UIPopoverControllerDelegate&#39;方法:

// refreshes the rect from where the popover is shown after interface orientations.
// this method is necessary and recommended by apple's documentation
- (void) popoverController : (UIPopoverController*) popoverController willRepositionPopoverToRect : (inout CGRect*) rect inView : (inout UIView*__autoreleasing*) view
{
    *rect = _buttonRectForPopoverController;
}