iOS8新特性(1)-UIPopoverPresentationController使用

从iOS 8开始,苹果提出新的 UIPopoverPresentationController代替UIPopoverController:

新的UIPopoverPresentationController使用方法如下:

    // 创建将要显示的Controller
    DJCategoryViewController *categoryVC = [[DJCategoryViewController alloc] init];
    // 设置控制器View的显示大小
    categoryVC.preferredContentSize = CGSizeMake(300, 360);
    // 设置Modal类型
    categoryVC.modalPresentationStyle = UIModalPresentationPopover;
    // 获取Popover
    UIPopoverPresentationController *categoryPopover = categoryVC.popoverPresentationController;
    // 相对于哪个View来显示
    categoryPopover.sourceView = self.categoryItem.customView;
    // 显示位置
    categoryPopover.sourceRect = self.categoryItem.customView.bounds;
    // 设置popover箭头的显示方向
    categoryPopover.permittedArrowDirections = UIPopoverArrowDirectionAny;
    // 跳转
    [self presentViewController:categoryVC animated:YES completion:nil];

 

posted @ 2017-01-04 21:42  夜行过客  阅读(1779)  评论(0编辑  收藏  举报