今天第一次用了UIPopoverController这个类,但是在设置大小的时候出现了一个问题,先把代码贴出来:
- (void)popoverView
{
UIViewController *viewController = [[UIViewController alloc]init];
viewController.view.backgroundColor = [UIColor greenColor];
viewController.contentSizeForViewInPopover = CGSizeMake(400, 400);
popoverController = [[UIPopoverController alloc]initWithContentViewController:viewController];
popoverController.delegate = self;
popoverController.popoverContentSize = CGSizeMake(100, 100);
CGRect rect = CGRectMake(100, 280, 0, 0);
[popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[viewController release];
}
当我试图通过修改绿色的的size大小来修改里面contentview的大小,发现根本不起作用,我以为里面的view和外面的popover是独立的,查了一下官方文档,说明如下:If the popover controller displaying the view controller sets its popoverContentSize
property, the popover controller overrides the values set in the view controller’s contentSizeForViewInPopover
property.
紫色的属性覆盖了绿色的属性,只有popoverContentSize生效,问题就出现在这里。