UIPopover - 将子视图的帧大小更改为 contentViewController.view 的规定方法是什么?
我在尝试更改 UIPopover 的 contentViewController 中视图的帧大小或隐藏属性时没有取得任何成功。我尝试以编程方式更改 contentViewController.view 子视图的帧大小,但无法更改它。无论 xib 初始化什么帧,它都会保留。现在,我正在尝试为每个设备方向添加两个具有正确帧大小的子视图,并使用隐藏属性使具有正确帧大小的视图可见。 xib 最初有每个“.hidden:YES”。我无法使用“.hidden:NO”使其中之一可见。
具体来说,我在弹出窗口中有一个 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];
I'm not having any success trying to change the frame size or the hidden property of views in the contentViewController of my UIPopover. I tried to just alter the frame size of a subview of the contentViewController.view programmatically, but I couldn't alter it. Whatever frame the xib initialized it retained. Now I'm tryin 2 subviews with correct frame sizes for each device orientation, and useing the hidden property to make the view with the correct frame size visible. The xib initially has each ".hidden:YES". I'm not able to use ".hidden:NO" make one of them visible.
Specifically I've a UIImageView in the popover that I want as large as possible in each orientation, while retaining the aspect ratio of the picture it contains.
Some code...
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以更改弹出窗口的大小:
[saveOrPrintPopover setPopoverContentSize:CGSizeMake(320, 560)];
并且您的内容视图应正确配置为自动调整大小。
You can change size of popover:
[saveOrPrintPopover setPopoverContentSize:CGSizeMake(320, 560)];
And your content view should be configured properly to autoresize.