UIPopoverPresentationController的使用

UIPopoverPresentationController是iOS8引入的弹出控件,不同于UIAlertController。它是UIViewController的属性,通过设置sourceRect、permittedArrowDirections、代理方法等实现弹出效果。代码示例中展示了如何配置并使用该控件,包括点击蒙版消失的设置和弹出视图关闭后的回调方法。
摘要由CSDN通过智能技术生成

UIPopoverPresentationController是个什么?

我理解中的UIPopoverPresentationController是个弹出的控件,与UIAlertController类似,但又不同。UIPopoverPresentationController是iOS8以后新增的,是UIViewController的属性。使用的的时候,需要创建的是UIViewController。

先看一段代码:

    UIViewController *functionListVC = [[UIViewController alloc] init];
    functionListVC.modalPresentationStyle = UIModalPresentationPopover;
    
    UIPopoverPresentationController *pover = functionListVC.popoverPresentationController;
    pover.delegate = self;
    pover.sourceView = testButton;
    pover.sourceRect = testButton.bounds;
    pover.backgroundColor = [UIColor colorWithRed:63/255.0 green:66/255.0 blue:75/255.0 alpha:1.000];
    pover.permittedArrowDirections = UIPopoverArrowDirectionAny;
    [self presentViewController:functionListVC animated:YES completion:nil];
sourceView是指弹出时所参照的视图,与弹框的位置有关。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值