UIPopover - 将子视图的帧大小更改为 contentViewController.view 的规定方法是什么?

发布于 2024-11-09 03:13:11 字数 1754 浏览 0 评论 0原文

我在尝试更改 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末染殇 2024-11-16 03:13:11

您可以更改弹出窗口的大小:

[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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文