UIPopoverPresentationController 用法


MyViewController *viewController = [[MyViewController alloc] init];

viewController.modalPresentationStyle = UIModalPresentationPopover;

emptyViewController.preferredContentSize = CGSizeMake(300, 200);

UIPopoverPresentationController *pop = emptyViewController.popoverPresentationController;

pop.sourceRect = CGRectMake(10, 10, 20, 20);

pop.sourceView = self.view;

pop.delegate = self;

[self.navigationController presentViewController:emptyViewController animated:YES completion:nil];

如果想在 iPhone 上也显示为非全屏的弹出框,需要实现 UIPopoverPresentationControllerDelegate 协议的方法,返回 UIModalPresentationNone 即可:

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {

   return UIModalPresentationNone;

}

你可能感兴趣的:(UIPopoverPresentationController 用法)