应用解析 UIPopoverPresentationController是iOS8后系统新引入的控制器,其可以很好的兼容iPhone与iPad。 对象 UIPopoverPresentationController* con = tabCon.popoverPresentationController; //设置弹出的基准视图 con.sourceView = self.view; [self presentViewController:tabCon animated:YES completion:nil]; UIPopoverPresentationController UIPopoverPresentationControllerDelegate中的方法如下: //控制器将要弹出时调用 - (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController; //控制器接收到弹出消息时调用 - (void)popoverPresentationController:(UIPopoverPresentationController
而现在使用UIPopoverPresentationController不再需要对设备进行判断了。 UIPopoverPresentationController不需要你去创建。 200);//popover视图的大小 view.modalPresentationStyle = UIModalPresentationPopover;//如果没有这句,pop不会被初始化 UIPopoverPresentationController
API NOTE 在iOS 8及以后的系统中,你可以使用UIPopoverPresentationController来显示一个弹出框。 UIPopoverPresentationController 定义了一个协议来让你调整你的弹出内容的显示风格去适应当前的显示环境。
NSPopover 提供了在屏幕内容视图上显示额外信息内容的一种方式(其实这个类似于在iPad开发中是常见的UIPopoverPresentationController),它的定位相对与现有内容。
iPad或其他常规宽度的设备时,就会得到一个运行时异常: Terminating app due to uncaught exception ‘NSGenericException’, reason: ‘UIPopoverPresentationController 配置该弹出框的代码如下: Objective-C版本: UIPopoverPresentationController *popover = alertController.popoverPresentationController permittedArrowDirections = UIPopoverArrowDirection.Any } iPad上的上拉菜单效果 UIPopoverPresentationController
API注释 在iOS 8以及以上版本里,你可以使用UIPopoverPresentationController来展示一个浮出层。 UIPopoverPresentationController定义了一种委托,让你可以调整浮出层的内容样式,让它能够更好地适应当前的屏幕内容。