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

推荐阅读更多精彩内容

  • 1. 人若没有梦想,不如死去。— 史蒂芬•霍金 2 要为灵魂找一个美丽的归宿,不要为肉体找一块豪华的坟墓。 3 只...
    能照阅读 4,438评论 0 0
  • 鹈鹕总经理:霍勒迪现在最重要的身份是丈夫 摘要:戴维斯和庞德塞特还有几名鹈鹕队员到霍勒迪家里看望他,和他一起训练。...
    prudenceli阅读 1,306评论 0 0
  • iOS开发中我们会遇到程序抛出异常退出的情况,如果是在调试的过程中,异常的信息是一目了然,我们可以很快的定位异常的...
    清晨十分的阳光阅读 9,339评论 16 44
  • 欲识金银气,多从黄白游。 一生痴绝处,无梦到徽州。 ...
    一个王大可阅读 5,268评论 22 19