UIKit-UIPopoverPresentationController(弹出的view)

在当前view情况下,点击view上面一个button,弹出一个view

UIPopoverPresentationController主要用于管理弹出的view的形式,比如弹出位置和弹出方向

//customViewController.m
[self.showPopViewBtn addTarget:self action:@selector(showPopoverPresentationWithParentViewC) forControlEvents:UIControlEventTouchUpInside];//用一个按钮时间来触发

- (void)showPopoverPresentationWithParentViewC
{
    
    
    NSLog(@"%s",__func__);
    UIViewController* popupViewC = [[UIViewController alloc]init];//这部分是要被弹出的view
    popupViewC.view.backgroundColor = [UIColor redColor];
    UIPopoverPresentationController* popoverPresentationC = [popupViewC popoverPresentationController];//使用popoverPresentationC来管理弹出PopupViewC的设置
    popoverPresentationC.sourceView = self.view;//指定弹出试图控制器的源视图,弹出的popupViewC的view是以源视图位置来确定弹出的位置和箭头方向
    popoverPresentationC.sourceRect = self.view.bounds;
    popoverPresentationC.backgroundColor = [UIColor blueColor];//目前这个没用 搞不清楚这个和pViewC.view.backgroundColor = [UIColor redColor];区别
    popoverPresentationC.permittedArrowDirections = UIPopoverArrowDirectionUp;//控制popupViewC弹出的方向,目前是从下往上弹出

    [self dismissViewControllerAnimated:NO completion:nil];
    [self presentViewController:popupViewC animated:YES completion:nil];
    
}

猜你喜欢

转载自blog.csdn.net/qq_43535469/article/details/131419705