uiview自动调整大小

发布于 2024-09-11 17:47:38 字数 1437 浏览 1 评论 0原文

我在 UITabController 中有一个 UIView。 其中有一个UITableView

在呼叫状态栏中切换时,它不会执行任何操作,并且视图不会自动调整大小。

它根据应用程序启动时是否切换调用 UIStatusBar 来假定正确的大小,但如果在应用程序运行时切换 UIStatusBar 则不会发生任何变化。

另一个带有 UINavigationController 的选项卡视图似乎可以很好地调整大小。

这是代码

if ([indexPath indexAtPosition:0] == 0 || [indexPath indexAtPosition:0] == 1) {
        if (!airportChooser) {
            airportChooser = [[AirportChooserController alloc] init];
            airportChooser.targetController = self;
            airportChooser.view.autoresizesSubviews = YES;  
            airportChooser.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
            [airportChooser.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
        }
        airportChooser.target = [indexPath indexAtPosition:0];
        [self.parentViewController.parentViewController.view addSubview:airportChooser.view];
        self.parentViewController.parentViewController.view.autoresizesSubviews = YES;
        self.parentViewController.parentViewController.view.contentMode = UIViewContentModeRedraw;
        [self.parentViewController.parentViewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
        airportChooser.view.contentMode = UIViewContentModeRedraw;
        //[airportChooser open];
    }

I have a UIView in a UITabController.
And there is a UITableView in it.

When toggling in call status bar it doesn't do anything and the view is not automatically resized.

It assumes the right size based on whether the in call UIStatusBar was toggled when the app starts but if the UIStatusBar is toggled whilst the app is running nothing changes.

Another tab view with a UINavigationController seems to resize fine.

Here is the code

if ([indexPath indexAtPosition:0] == 0 || [indexPath indexAtPosition:0] == 1) {
        if (!airportChooser) {
            airportChooser = [[AirportChooserController alloc] init];
            airportChooser.targetController = self;
            airportChooser.view.autoresizesSubviews = YES;  
            airportChooser.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
            [airportChooser.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
        }
        airportChooser.target = [indexPath indexAtPosition:0];
        [self.parentViewController.parentViewController.view addSubview:airportChooser.view];
        self.parentViewController.parentViewController.view.autoresizesSubviews = YES;
        self.parentViewController.parentViewController.view.contentMode = UIViewContentModeRedraw;
        [self.parentViewController.parentViewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
        airportChooser.view.contentMode = UIViewContentModeRedraw;
        //[airportChooser open];
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

_蜘蛛 2024-09-18 17:47:38

您是否正确设置了 UIView 的调整大小掩码?您可以在Interface Builder中的尺寸选项卡中进行设置,您可以单击红线。

您还可以使用以下内容在代码中设置它:

[view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 
                          UIViewAutoresizingFlexibleHeight];

同时确保超级视图已将 autoresizesSubviews 设置为 YES。

您可以在 UIView 文档

Did you set the resizing mask of the UIView correctly? You can set it in Interface Builder in the size tab, it's the red lines that you can click.

You can also set it in code using something like:

[view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 
                          UIViewAutoresizingFlexibleHeight];

Also make sure the superview has set autoresizesSubviews to YES.

You can find more information about this in the UIView documentation.

2024-09-18 17:47:38

虽然克拉斯派特的答案是有道理的,并且在某些情况下可能是正确的答案
在我的具体情况下,这是因为我使用 addSubview 而不是 PushViewController:viewAnimated:NO; 将子视图添加到 UINavigationController 的视图中。

Whilst klaaspeiter's answer makes sense and in some cases may be the right answer
in my specific case it was because I was adding a sub view to a UINavigationController's view with addSubview instead of pushViewController:view animated:NO;

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