ios气泡弹出框popover效果系统原生方法实现
#pragma mark右bar点击事件
- (void)rightBarClick{
XiXiRegisterPopoverVC *view = [[XiXiRegisterPopoverVCalloc]init]
// 设定大小(此处也可不做设置,不做设置的效果如下图)
view.preferredContentSize =CGSizeMake(150,100);
// 初始化
view.modalPresentationStyle =UIModalPresentationPopover;
UIPopoverPresentationController *popVC = view.popoverPresentationController;
// 设置代理(iPhone必须设置代理才能显示)
popVC.backgroundColor = [UIColorcolorWithRGB:0x000000alpha:0.8];
popVC.delegate =self;
// 获取按钮
popVC.barButtonItem =self.navigationItem.rightBarButtonItem;
// 退出视图
[selfpresentViewController:viewanimated:YEScompletion:nil];
}
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
// 此处为不适配(如果选择其他,会自动视频屏幕,上面设置的大小就毫无意义了)
returnUIModalPresentationNone;
}
// ------------------------华丽的分割线-----------
如果想要在按钮点击的时候触发
按钮点击按如下方式实现
- (IBAction)btnClick:(UIButton *)sender {
WFPopViewController *viewVC = [[WFPopViewControlleralloc] init];
viewVC.preferredContentSize =CGSizeMake(150,100);
viewVC.modalPresentationStyle =UIModalPresentationPopover;
UIPopoverPresentationController *popVC = viewVC.popoverPresentationController;
popVC.delegate =self;
// 气泡依附于哪个view弹出
popVC.sourceView = sender;
// 气泡从哪个位置弹出,是以按钮的上边中心点即(sender.width/2,0)为坐标原点。
popVC.sourceRect =CGRectMake(0, sender.frame.size.height,0, 0);
// > 箭头的指向(上,下,左,右)
popVC.permittedArrowDirections =UIPopoverArrowDirectionUp;
[selfpresentViewController:viewVCanimated:YEScompletion:nil];
}