UIPopoverPresentationController

1.效果如下:

UIPopoverPresentationController_第1张图片
27.png
  1. 实现代码如下:
    - (IBAction)btnClick:(UIButton *)sender {
        
        MenuController *menu = [[MenuController alloc] initWithStyle:UITableViewStylePlain];

        menu.modalPresentationStyle = UIModalPresentationPopover; 
        menu.preferredContentSize = CGSizeMake(150, 200);
        
        UIPopoverPresentationController *p = menu.popoverPresentationController;
        p.delegate = self;
        p.sourceView = sender;
        p.sourceRect = CGRectMake(0, 0, sender.frame.size.width, sender.frame.size.height);
        [self presentViewController:menu animated:YES completion:nil];
    }
#pragma mark - UIPopoverPresentationControllerDelegate   
  - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
        return UIModalPresentationNone;
    }

你可能感兴趣的:(UIPopoverPresentationController)