iOS8新特性(1)-UIPopoverPresentationController使用

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

新的UIPopoverPresentationController使用方法以下:code

    // 建立将要显示的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];
相关文章
相关标签/搜索