popover弹出视图

UIPopoverController 在iOS9被废弃了。

PopoverViewController *vc = [PopoverViewController new];弹出视图要提前实现样式等
vc.modalPresentationStyle = UIModalPresentationPopover;设置展示模式为popover
vc.preferredContentSize = CGSizeMake(80, 126);设置大小
UIPopoverPresentationController *popovervc = vc.popoverPresentationController;popoverPresentationController是vc的扩展属性,PopoverPresentationController不用新建直接获取vc的即可
popovervc.barButtonItem = self.rightBarButton;决定展示的视图依附于那个按钮
popovervc.delegate = self;
popovervc.permittedArrowDirections = UIPopoverArrowDirectionUp;箭头方向
[self presentViewController:vc animated:YES completion:nil];合适时机弹出vc

实现代理方法

/* For iOS8.0, the only supported adaptive presentation styles are UIModalPresentationFullScreen and UIModalPresentationOverFullScreen. */
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
    return UIModalPresentationNone;设置为none 才能弹出popover样式
}
-(UIViewController *)presentationController:(UIPresentationController *)controller viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style
{
    return [[UINavigationController alloc] initWithRootViewController:controller.presentedViewController];
}

你可能感兴趣的:(popover弹出视图)