隐藏/显示导航栏上的视图框架更改?
在我的应用程序中,
我有带有根视图控制器的导航控制器。
显示/隐藏导航栏效果很好。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
BOOL navbarhide=[self.navigationController.navigationBar isHidden];
[self.navigationController setNavigationBarHidden:!navbarhide animated:YES];
}
效果很好,但是,
当隐藏导航栏时,视图框架会发生变化。
当导航栏未隐藏时,视图框架会发生变化。
提前致谢...
编辑设置设置 self.view.frame 不会产生任何效果。
In My Application,
I have Navigation Controller with root view controller.
To show/hide navigation bar which works fine.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
BOOL navbarhide=[self.navigationController.navigationBar isHidden];
[self.navigationController setNavigationBarHidden:!navbarhide animated:YES];
}
Works good but,
When navigation bar is hidden then view frame changes.
When navigation bar is not hidden then view frame changes.
Thanks in Advance...
Edit Setting set self.view.frame does not make any effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我有同样的问题。在我的项目中,这是因为视图是滚动视图。如果您的视图是滚动视图或表格视图,您可以尝试以下操作:
我将以下代码添加到控制器中。
希望它可以帮助你。
I have the same problem. In my project, it is because the view is scroll view. If your view is a scroll view or table view, you can try this:
I add below code to the controller.
Hope it can help you.
您无法更改
self.view
的框架。我没有使用setNavigationBarHidden:
隐藏导航栏,而是直接改变self.navigationController.navigationBar的frame。这样,self.view.frame
就不会改变。You cannot change the frame of
self.view
. I don't usesetNavigationBarHidden:
to hidden the navigation bar, but directly change the frame of self.navigationController.navigationBar. In this way,self.view.frame
won't change.我在全屏显示 UIView 时遇到了这个问题。调整框架大小对我有用。 (Swift)
隐藏导航栏:
再次显示导航栏:
I had this problem while displaying UIView fullscreen. Resizing frame worked for me. (Swift)
hiding navigationBar:
showing navigationBar again:
我认为这是默认功能,您无法更改,但您可以使用以下代码更改按钮的位置
myButton.frame = CGRectMake(X, Y, Height, Width);
隐藏导航栏后。
I think this is by default functionality which cannot be changed by you, but you change the position of the button by using following code
myButton.frame = CGRectMake(X, Y, Height, Width);
after hiding the navigation bar.
我想这可能对你有帮助
i think this may help you
显示和隐藏导航栏时更改 self.view.frame
change the self.view.frame when you are showing and hiding the navigation bars