旋转时调整 UINavigationBar 的大小
我有一个 UIViewController 的子类,它处理 UIView。视图控制器以模态方式呈现(它从屏幕底部向上滑动)。在视图的顶部,我添加了一个导航栏。请注意,该栏不是由导航控制器处理的。
我想让导航栏在视图旋转到横向时缩小高度(类似于 UINavigationController 处理它时的行为)。但是,我无法在 IB 中将其自动调整大小掩码设置为灵活高度,并且在代码中这样做会导致导航栏完全消失。
有办法做到这一点吗? UINavigationController 是如何完成的?
PS 我宁愿不必诉诸缩放变换,因为这会弄乱标题中的文本。
编辑:我在一点帮助下解决了这个问题,请阅读下面发布的答案。
I have a subclass of UIViewController which handles a UIView. The viewcontroller is presented modally (it slides up from the bottom of the screen). At the top of the view, i have added a navigation bar. Note that this bar is not handled by a navigation controller.
I want to get the navbar to shrink in height when the view rotates to landscape (similar to how it behaves when it is handled by a UINavigationController). However, I can't set its autoresizing mask to flexible height in IB, and doing so in code causes the navbar to disappear completely.
Is there a way to do this? How is it done by the UINavigationController?
P.S. I would prefer not having to resort to a scaling transform, since this would mess up the text in the title.
EDIT: I solved it with a little help, read the answer posted below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不直接检查 viewWillAppear 以及 didRotateFromInterfaceOrientation 中的当前方向,并设置适当的框架,而不是设置它的自动调整大小蒙版?
Rather than set it's autoresizing mask, why don't you just check the current orientation in viewWillAppear, as well as in didRotateFromInterfaceOrientation, and set the appropriate frame?
我找到了解决方案,事后看来我觉得很愚蠢。我只需在导航栏的自动调整大小蒙版中包含灵活的底部边距。感谢此线程中的用户 RayNewbie,它为我指出了解决方案:
http:// /discussions.apple.com/thread.jspa?messageID=8295525
I found the solution, and in hindsight i feel rather stupid. I just had to include flexible bottom margin in the navbar's autoresize mask. Credit is due to user RayNewbie in this thread, which pointed me to the solution:
http://discussions.apple.com/thread.jspa?messageID=8295525