在 tabbarcontroller 顶部加载视图

发布于 2024-09-14 23:17:10 字数 281 浏览 4 评论 0原文

我有一个标签栏控制器,在触摸视图导航右键之一中的按钮时,我想在其顶部加载一个(导航控制器+视图)。其顶部的视图是半透明的,我应该能够看到选项卡栏控制器中的内容。

我尝试使用 [self.tabbarcontroller.view addSubview:navController];

我工作得很好,而且工作得很好。但是当我尝试在横向视图中做同样的事情时,它只占据了屏幕的一半。应该做什么?有没有办法解决这个问题

我可以使用窗口加载我的新视图吗?它会占据整个屏幕吗?我尝试了自动调整蒙版大小,但没有效果

I have a tabbar controller and on touching a button in one of view's navigation right button i want to load a (nav controller + view )on top of it. The view which is on the top of it is semi transparent and i should be able to see the content in the tabbar controller.

I tried using the [self.tabbarcontroller.view addSubview:navController];

I worked perfectly and it is working fine. But when i tried to do the same thing in landscape view it is just occupying half the screen. what should be done ? is there a way to fix this issue

can i use the window to load my new view ? will it occupy the entire screen ? i tried autoresize masks and there is no effect

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

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

发布评论

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

评论(2

雨后咖啡店 2024-09-21 23:17:10

navController/tabbarcontroller 的边界是什么?您是否正确设置了窗口的设置?

您可以轻松输出它:

NSLog(@"navController bounds: %@",NSStringFromCGRect(navController.view.bounds));

What is the bounds of the navController/tabbarcontroller? Are you setting correctly to that of the window?

You can output it easily:

NSLog(@"navController bounds: %@",NSStringFromCGRect(navController.view.bounds));
∞觅青森が 2024-09-21 23:17:10

您的意思是 addSubview:navController.view 吗?我不认为你可以将视图控制器视为视图。

一般来说,在框架管理的类之外使用 UIViewController 时需要小心。 UIKit 自动处理它所知道的视图控制器的 viewWillAppear/autorotation 等内容,但它不知道您随机添加其视图作为子视图的 VC。

编辑:如果您只需要它看起来是透明的,您可以使用类似的东西

UIGraphicsBeginImageContextWithOptions(tabBarController.view.size, 0, 0);
[tabBarController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

,然后使用 img 作为视图背景。它不会为背景中的内容设置动画,但如果您不需要这样做,它比将大量透明视图堆叠在一起要快得多。

Do you mean addSubview:navController.view? I didn't think you could treat view controllers as views.

In general, you need to be careful when using UIViewController outside of the framework-managed classes. UIKit automatically handles stuff like viewWillAppear/autorotation for the view controllers that it knows about, but it doesn't know about the VCs whose views you randomly add as subviews.

EDIT: If all you require is that it appears to be transparent, you can use something like

UIGraphicsBeginImageContextWithOptions(tabBarController.view.size, 0, 0);
[tabBarController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

and then use img as the view background. It won't animate the stuff in the background, but provided you don't need this, it's much faster than having lots of transparent views stacked on top of each other.

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