UIPresentationController

本文介绍了一个使用Swift实现的iOS应用中地址选择功能的方法。通过一个按钮触发Popover视图展示地址选择界面,并且能够调整Popover视图的大小、位置及样式。此外,还展示了如何在点击Popover内的按钮后关闭该视图并打开另一个新的地址选择界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-(void)clickAdrress:(UIButton *)sender{

    NSLog(@"点击地址弹出控制器");

    _addressPopone = [addressPopViewController new];

    _addressPopone.view.backgroundColor = [UIColor clearColor];

    _addressPopone.preferredContentSize = CGSizeMake(self.view.frame.size.width-10-10, self.view.frame.size.height/2);

    _addressPopone.modalPresentationStyle = UIModalPresentationPopover;

    _addressPopone.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;

    _redView = [[UIView alloc]init];

    _redView.frame = _addressPopone.view.frame;

    _redView.backgroundColor = [UIColor clearColor];

    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(40, 40, 40, 40)];

    btn.backgroundColor = [UIColor blueColor];

    [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];

    [_redView addSubview:btn];

    

    

    [_addressPopone.view addSubview:_redView];

    self.popover = _addressPopone.popoverPresentationController;//初始化一个

    self.popover.delegate = self;

    self.popover.sourceView = self.addressBtn;

    self.popover.sourceRect = self.addressBtn.bounds;

    //self.popover.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];

    self.popover.backgroundColor = [UIColor clearColor];

    [self presentViewController:_addressPopone animated:YES completion:nil];

    

}

-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{

    return UIModalPresentationNone;

    

}

-(void)clickBtn:(UIButton *)sender{

    

    [self dismissViewControllerAnimated:YES completion:nil];

//    

    addressPopViewController *addressPop = [[addressPopViewController alloc]init];

    addressPop.modalPresentationStyle = UIModalPresentationFormSheet;

    [self presentViewController:addressPop animated:YES completion:nil];

   

}


-(void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController{

    [self dismissViewControllerAnimated:YES completion:nil];

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值