Navigation Controller that doesn#39;t use the whole screen(不使用整个屏幕的导航控制器)
问题描述
我有一个导航控制器,我不想用完整个屏幕.特别是,我想在屏幕顶部的栏中放置一个徽标图像.不幸的是,导航控制器似乎不是这样设计的.在界面生成器中,我不能让它占据屏幕的一部分.您将如何实现顶部的徽标图像和占据屏幕其余部分的导航控制器的效果?
我自己没有这样做,但应该很简单.您需要一个包装视图控制器作为其父级(我们称之为 MyWrapperViewController),其视图层次结构最终可能如下所示:
徽标视图可以是 UIView、UIImageView 或任何适合内容的类.
当您在某处为您的 MyWrapperViewController 类创建 UINavigationController 时,您可以调整其 view bounds 的大小小于全屏(可能是屏幕大小减去您的徽标大小,并带有适当的 origin 偏移量,因此它位于徽标下方),然后将其添加为子视图.
I have a navigation controller which I don't want to use up the whole screen. In particular, I want to put a logo image in a bar at the top of the screen. Unfortunately, the navigation controller doesn't seem to be designed this way. In interface builder, I can't make it take up part of a screen. How would you achieve the effect of a logo image up the top and a navigation controller taking up the rest of the screen?
I haven't done this myself, but it should be pretty straight-forward. You'll need a wrapper view controller to be its parent (let's call it MyWrapperViewController), and its view hierarchy might ultimately look something like this:
UIView -+ (hooked up to the view outlet in MyWrapperViewController)
|
+-- UIView (Your logo goes here)
|
+-- UIView (The "child" navigation controller's view)
The logo view can be a UIView, or a UIImageView, or whatever class is appropriate for the content.
When you create a UINavigationController somewhere for your MyWrapperViewController class, you can resize its view bounds to something smaller than full-screen (perhaps the size of the screen minus the size of your logo, with an appropriate origin offset so it's below the logo), and then add it as a subview.
这篇关于不使用整个屏幕的导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:不使用整个屏幕的导航控制器
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
