UITabBarController - 初始框架和调整大小
我发现了这个: 子类 UITabBarController 来调整其框架 它解释了如何实现什么我的目标是在答案中。为了解释那里的帖子,您必须注册才能在 TabBarController 的选定视图更改时收到通知,然后在那里应用您的几何图形。否则它会被 TabBarController 震撼。
我正在尝试调整 UITabBarController 的大小,以在某些任务发生时显示 20px 高的状态消息。奇怪的是,如果我单步执行调整 TabBarController 大小的方法,框架的原点就会改变。
当视图首次出现时,UITabBarController 的 y 原点设置为 0。即使 applicatioinScreen y.origin 为 20。如果我在应用程序首次加载时调整大小,一切都会关闭。子视图不会调整大小。第一次调整大小后,如果我查看不同的选项卡,TabBarController 会将自身调整为正确的大小,并且对调整大小方法的后续调用确认了这一点。
这就是我安装 UITabBarcontroller 的方式:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[AppController getGroupViewControllerArray] animated:NO];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
return YES;
}
这就是我调整 TabBarController 大小的方式:
-(void)resizeTabToShowActivity {
CGRect newFrame = mainTabBarController.view.frame;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
newFrame.origin.y = applicationFrame.origin.y + 20;
newFrame.size.height = applicationFrame.size.height - 20;
mainTabBarController.view.frame = newFrame;
}
我注意到,如果我在窗口中安装 TabBarController 后直接调整大小,则一切正常。出于调试目的,我也将调整大小方法移至 AppDelegate 中,但仍然没有任何乐趣。
谢谢
I found this: Subclass UITabBarController to adjust its frame which explains how to achieve what I was aiming for in the answer. To paraphrase the post there, you have to register to be notified when the TabBarController's selected view changes, and then apply your geometry there. Otherwise it gets blown away by the TabBarController.
I am attempting to resize my UITabBarController to show a 20px high status message when certain tasks are ocurring. The curious thing is that if I step through the method which resizes the TabBarController, the origin of the frame changes.
When the view first appears, the UITabBarController's y origin is set to 0. Even though the applicatioinScreen y.origin is 20. If I resize when the app first loads, everything is off. The subviews do not resize. After this first resize, if I view a different tab, the TabBarController adjusts itself to the proper size, and subsequent calls to my resizing method confirm this.
This is how I am installing the UITabBarcontroller:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[AppController getGroupViewControllerArray] animated:NO];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
return YES;
}
And this is how I am resizing the TabBarController:
-(void)resizeTabToShowActivity {
CGRect newFrame = mainTabBarController.view.frame;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
newFrame.origin.y = applicationFrame.origin.y + 20;
newFrame.size.height = applicationFrame.size.height - 20;
mainTabBarController.view.frame = newFrame;
}
I have noticed that if I resize directly after installing the TabBarController in the window, everything works fine. For debugging purposes, I've moved the resize method into the AppDelegate as well, and still no joy.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能够通过将 UITabBarController 包含在父 UIViewController 中并将父 UIViewController 作为应用程序的根视图控制器来调整其大小。
这是我的父 UIViewController
MyViewController1 和 MyViewController2 只是具有 UILabel 的通用 UIViewController 子类。
这是我的应用程序委托代码,用于加载父 UIViewController
I was able to resize a UITabBarController by containing it within a parent UIViewController, and making the parent UIViewController as the root view controller for the app.
Here's my parent UIViewController
MyViewController1 and MyViewController2 are just generic UIViewController subclasses that have a UILabel.
Here's my app delegate code that loads the parent UIViewController
UITabBarController 通常从
wantsFullScreenLayout
返回 YES,这意味着当用作根视图控制器时,其视图的大小将适合全屏,包括状态栏下方的区域。然后,控制器根据需要调整其子视图的大小,以避开状态栏下方的区域。您可以尝试将
wantsFullScreenLayout
设置为 NO,这应该使其大小不会像您预期的那样位于状态栏下方。The UITabBarController normally returns YES from
wantsFullScreenLayout
, which means that its view when used as the root view controller will be sized for the full screen including the area under the status bar. The controller then sizes its subviews to avoid the area under the status bar, as needed.You can try setting
wantsFullScreenLayout
to NO, which should make it be sized to not be under the status bar as you seem to be expecting.在 UITabBarController 子类上尝试一下:
Try this on UITabBarController subclass: