本文最后更新于:2021年12月22日 中午
目录
一、常见属性
属性 |
描述 |
sourceView |
箭头所指的对应的视图,sourceRect会以这个视图的左上角为原点 |
sourceRect |
箭头所指对应的区域,以sourceView为参照 |
permittedArrowDirections |
箭头方向 |
二、常见方法
UIAdaptivePresentationControllerDelegate代理方法
1 2 3 4
| - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{ return UIModalPresentationNone; }
|
UIPopoverPresentationControllerDelegate代理方法
1 2 3 4 5 6 7 8 9 10 11 12 13
|
-(BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController{ return YES; }
-(void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController{ NSLog(@"弹框已经消失"); }
|
三、示例代码
1. 遵守协议
实现协议UIPopoverPresentationControllerDelegate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller { return UIModalPresentationNone; }
- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController { return YES; }
- (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController { }
|
2. 触发弹窗
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| - (void)popAction:(UIButton *)button { UIViewController *vc = [UIViewController new]; vc.preferredContentSize = CGSizeMake(300, 500); vc.modalPresentationStyle = UIModalPresentationPopover; UIPopoverPresentationController *pover = vc.popoverPresentationController; pover.delegate = self; pover.sourceView = button; pover.sourceRect = button.bounds; pover.backgroundColor = [UIColor lightGrayColor]; pover.permittedArrowDirections = UIPopoverArrowDirectionAny; [self presentViewController:vc animated:YES completion:^{ }]; }
|
联系方式
邮箱: xiebangyao_1994@163.com
相关账号: