首页 > 代码库 > presentation Controllers的使用

presentation Controllers的使用

presentation Controllers的使用

by 伍雪颖



@interface ViewController ()<UIPopoverPresentationControllerDelegate, UIAdaptivePresentationControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)show:(id)sender {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    TestViewController *contentViewController = [storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([TestViewController class])];
    contentViewController.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *detailPopover = contentViewController.popoverPresentationController;
    detailPopover.delegate = self;
    detailPopover.barButtonItem = sender;
    detailPopover.permittedArrowDirections = UIPopoverArrowDirectionAny;
    [self presentViewController:contentViewController animated:YES completion:nil];
}

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
    return UIModalPresentationNone;
}

- (UIViewController *)presentationController:(UIPresentationController *)controller viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style {
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller.presentedViewController];
    return navController;
}


presentation Controllers的使用