Unwanted margin UIPopoverController

梦想的初衷 提交于 2019-12-06 06:08:39

问题


When I present my popover in a view and place it at the side of the view. There is always a small margin, causing the popover to not stick to the side.

UIViewController *vc =  [self getViewController:@"popover" fromStoryboard:@"Main"];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:vc];
[popover presentPopoverFromRect:CGRectMake(1100, 0, -65, 65)
                              inView:self.view
            permittedArrowDirections:UIPopoverArrowDirectionUp
                       animated:YES];
[vc setPreferredContentSize:CGSizeMake(300, 300)];

How do I prevent this margin and show my popover sticking to the side of the view?

Thanks


回答1:


I fixed this issue by adding my own UIPopoverBackgroundView implementation where I set my own contentview insets.

+ (UIEdgeInsets)contentViewInsets {
    return UIEdgeInsetsMake(-10, -10, -10, -10);
}

and adding this backgroundview to my popovercontroller

[self.popover setPopoverBackgroundViewClass:[MyPopoverBackgroundView class]];


来源:https://stackoverflow.com/questions/31023234/unwanted-margin-uipopovercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!