popoverPresentationController UIPopoverController 使用方法详解(气泡控制器)

 之前iPad特有的控件,现在iPhone亦可使用。

 点击按钮,弹出popOverVC.

按钮的点击事件:

- (IBAction)pickOrderAction:(UIButton *)sender {
    
    // > 初始化要弹出的控制器
    UIViewController * vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor blueColor];
     // > 设置弹出的控制器的显示样式
    vc.modalPresentationStyle = UIModalPresentationPopover;
     // > 弹出模式
    vc.modalTransitionStyle   = UIModalTransitionStyleFlipHorizontal;
    // > 弹出控制器的尺寸
    vc.preferredContentSize = CGSizeMake(300, 150);
    // > 弹出控制器的箭头指向的view
    vc.popoverPresentationController.sourceView = sender;
    // > 弹出视图的箭头的“尖”的坐标 - 以sourceView的(0,0,0,0)为基准结合sourceRect。系统默认width/2使用。(sender.bounds的位置即:在sender的底部边缘居中)
    vc.popoverPresentationController.sourceRect = sender.bounds;
    // > 箭头的指向(上,下,左,右)
    vc.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
    // > presentVC
    [self presentViewController:vc animated:YES completion:nil];
}

 ENOUGH TO USE?

iPad使用以上方法就可实现弹出功能

 

以下是iPhone的实现方法

TipViewController 是一个自定义的UIViewController

使用时一定要设置代理。并实现此代理方法;

效果如图:

 

 

 /// 设置气泡 - 提示开播时间
        TipViewController * tipVC  = [[TipViewController alloc] init];
        tipVC.preferredContentSize = CGSizeMake(192, 56);
        tipVC.modalPresentationStyle = UIModalPresentationPopover;
        UIPopoverPresentationController * popVC = tipVC.popoverPresentationController;
        popVC.delegate = self;
        popVC.sourceView = startBtn;
        popVC.sourceRect = CGRectMake(startBtn.frame.size.width/2.0, 0, 0, 0);
        [self presentViewController:tipVC animated:YES completion:nil];
需要遵守的协议 UIPopoverPresentationControllerDelegate
#pragma mark - popViewController 的代理方法,实现该方法才能够局部弹出控制器
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{

    return UIModalPresentationNone;
}

 

转载于:https://www.cnblogs.com/code-Officer/p/6015547.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值