uiview自动调整大小
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否正确设置了 UIView 的调整大小掩码?您可以在
Interface Builder
中的尺寸选项卡中进行设置,您可以单击红线。您还可以使用以下内容在代码中设置它:
同时确保超级视图已将
autoresizesSubviews
设置为 YES。您可以在 UIView 文档。
Did you set the resizing mask of the
UIView
correctly? You can set it inInterface Builder
in the size tab, it's the red lines that you can click.You can also set it in code using something like:
Also make sure the superview has set
autoresizesSubviews
to YES.You can find more information about this in the UIView documentation.
虽然克拉斯派特的答案是有道理的,并且在某些情况下可能是正确的答案
在我的具体情况下,这是因为我使用 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;