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];
相關文章
相關標籤/搜索