UIPopoverPresentationController使用

从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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容