简体   繁体   中英

How to create popup in storyboard - iOS

I am creating iPhone application by using storyboard. In this, how to create a popup on storyboard and how to add and dismiss this popup on viewcontroller.

Popup Sample Image:

在此处输入图片说明

i want to add popup in storyboard like this:

在此处输入图片说明

You might create it like this (don't forget to add <UIPopoverControllerDelegate> to presenting view controller class)

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];

and somewhere else in your presenting view controller class an example `UIPopoverControllerDelegate' method:

// 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM