我正在使用故事板创建iPhone应用程序。在这里,如何在storyboard上创建弹出窗口以及如何在viewcontroller上添加和关闭此弹出窗口。
弹出示例图片:
我想在这样的故事板中添加弹出窗口:
答案 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;
}