从iOS 8开始,苹果提出新的 UIPopoverPresentationController代替UIPopoverController。代码如下:
//创建你需要显示的controller
UIViewController *cityAlertViewController = [[UIViewController alloc] init];
//这里自定义的view
DLpopupView *popupView = [[DLpopupView alloc] initWithFrame:CGRectMake(0.0, 0.0,
[300, 91) andRestorationName:@“DCpopupView”];
cityAlertViewController.view = popupView;
//设置modal类型
cityAlertViewController.modalPresentationStyle = UIModalPresentationPopover; cityAlertViewController.preferredContentSize = CGSizeMake(300, 91);
//配置 UIPopoverPresentationController
UIPopoverPresentationController *cityErrorPopover = cityAlertViewController.popoverPresentationController;
//设置代理
cityErrorPopover.delegate = self;
//设置相关属性
cityErrorPopover.sourceView = self.view;
cityErrorPopover.sourceRect = button.frame; cityErrorPopover.permittedArrowDirections =
UIPopoverArrowDirectionUp; cityErrorPopover.backgroundColor = greenNormal;
// pop跳转
[self presentViewController:cityAlertViewController animated:YES completion:nil];