我试图在我的UIPopover的contentViewController中更改视图的框架大小或隐藏属性没有任何成功。我试图以编程方式改变contentViewController.view的子视图的帧大小,但我无法改变它。无论xib初始化它的帧是什么。现在,我正在为每个设备方向尝试2个具有正确帧大小的子视图,并使用隐藏属性使视图具有可见的正确帧大小。 xib最初都有“.hidden:YES”。我无法使用“.hidden:NO”使其中一个可见。
具体来说,我在popover中有一个UIImageView,我想在每个方向尽可能大,同时保留它包含的图片的宽高比。
一些代码......
UIInterfaceOrientation interfaceOrientation = [self interfaceOrientation];
// If a saveOrPrintPopover is not already showing, create it.
if(self.saveOrPrintPopover){
[self closeSaveOrPrintPopover];
keyImageView.image = appDelegate.lineImage;
appDelegate.lineImage = NULL;
content.printView.image = NULL;
}else{
//////// UIPopoverController created here !
saveOrPrintPopover = [[UIPopoverController alloc] initWithContentViewController:content];
content.view.frame = CGRectMake(0, 0, 1024, 748);
SaveOrPrintViewController *cntrler = (SaveOrPrintViewController *)saveOrPrintPopover.contentViewController;
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
saveOrPrintPopover.popoverContentSize = CGSizeMake(748, 940);
cntrler.landscapeBackingView.hidden = YES;
cntrler.portraitBackingView.hidden = NO;
}
else {
saveOrPrintPopover.popoverContentSize = CGSizeMake(984, 664);
cntrler.landscapeBackingView.hidden = NO;
cntrler.portraitBackingView.hidden = YES;
}
[content.view setNeedsLayout];
[content.view layoutIfNeeded];
saveOrPrintPopover.delegate = self;
appDelegate.lineImage = keyImageView.image;
keyImageView.image = NULL;
}
[self showPopoverFromBarButtonItem];
答案 0 :(得分:1)
您可以更改popover的大小:
[saveOrPrintPopover setPopoverContentSize:CGSizeMake(320, 560)];
您的内容视图应正确配置为自动调整大小。