MyViewController *viewController = [[MyViewController alloc] init];
viewController.modalPresentationStyle = UIModalPresentationPopover;
emptyViewController.preferredContentSize = CGSizeMake(300, 200);
UIPopoverPresentationController *pop = emptyViewController.popoverPresentationController;
pop.sourceRect = CGRectMake(10, 10, 20, 20);
pop.sourceView = self.view;
pop.delegate = self;
[self.navigationController presentViewController:emptyViewController animated:YES completion:nil];
如果想在 iPhone 上也顯示為非全屏的彈出框,需要實現(xiàn) UIPopoverPresentationControllerDelegate 協(xié)議的方法,返回 UIModalPresentationNone 即可:
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}