隐藏/显示导航栏上的视图框架更改?

发布于 2024-12-10 00:28:16 字数 678 浏览 1 评论 0原文

在我的应用程序中,

我有带有根视图控制器的导航控制器。

显示/隐藏导航栏效果很好。

- (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.

When navigation bar is not hidden ..see the press button and view's origin is below the bar, I dont want like this I want it to stick at navigation bar's origin[at the top of the page]

It is fine view is at its original position when bar is hidden. I want view to be stick  at this position and turn bar hide/show without changing the view's frame.

Thanks in Advance...

Edit Setting set self.view.frame does not make any effect.

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

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

发布评论

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

评论(7

自由范儿 2024-12-17 00:28:16

我有同样的问题。在我的项目中,这是因为视图是滚动视图。如果您的视图是滚动视图或表格视图,您可以尝试以下操作:

我将以下代码添加到控制器中。

self.automaticallyAdjustsScrollViewInsets = NO;

希望它可以帮助你。

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.

self.automaticallyAdjustsScrollViewInsets = NO;

Hope it can help you.

悟红尘 2024-12-17 00:28:16

您无法更改 self.view 的框架。我没有使用setNavigationBarHidden:隐藏导航栏,而是直接改变self.navigationController.navigationBar的frame。这样,self.view.frame就不会改变。

CGRect frame = (navBarhidden) ? CGRectMake(0, -24,self.view.bounds.size.width,44) :      CGRectMake(0, 20,self.view.bounds.size.width,44);
self.navigationController.navigationBar.frame = frame;

You cannot change the frame of self.view. I don't use setNavigationBarHidden: to hidden the navigation bar, but directly change the frame of self.navigationController.navigationBar. In this way, self.view.frame won't change.

CGRect frame = (navBarhidden) ? CGRectMake(0, -24,self.view.bounds.size.width,44) :      CGRectMake(0, 20,self.view.bounds.size.width,44);
self.navigationController.navigationBar.frame = frame;
孤独陪着我 2024-12-17 00:28:16

我在全屏显示 UIView 时遇到了这个问题。调整框架大小对我有用。 (Swift)

隐藏导航栏:

    self.navigationController!.navigationBar.hidden = true
    self.view.frame.origin.y -= 64
    self.view.frame.size.height += 64.0

再次显示导航栏:

    self.navigationController!.navigationBar.hidden = false
    self.view.frame.origin.y += 64
    self.view.frame.size.height -= 64.0

I had this problem while displaying UIView fullscreen. Resizing frame worked for me. (Swift)

hiding navigationBar:

    self.navigationController!.navigationBar.hidden = true
    self.view.frame.origin.y -= 64
    self.view.frame.size.height += 64.0

showing navigationBar again:

    self.navigationController!.navigationBar.hidden = false
    self.view.frame.origin.y += 64
    self.view.frame.size.height -= 64.0
爱的那么颓废 2024-12-17 00:28:16

我认为这是默认功能,您无法更改,但您可以使用以下代码更改按钮的位置

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.

浮萍、无处依 2024-12-17 00:28:16

我想这可能对你有帮助

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
BOOL navbarhide=[self.navigationController.navigationBar isHidden];
[self.navigationController setNavigationBarHidden:!navbarhide animated:YES];
 if(navbarhide)
 self.view.frame=CGRectMake(0,0, 320, 480);
 else
  self.view.frame=CGRectMake(0,44, 320, 480);
 }

i think this may help you

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
BOOL navbarhide=[self.navigationController.navigationBar isHidden];
[self.navigationController setNavigationBarHidden:!navbarhide animated:YES];
 if(navbarhide)
 self.view.frame=CGRectMake(0,0, 320, 480);
 else
  self.view.frame=CGRectMake(0,44, 320, 480);
 }
凉墨 2024-12-17 00:28:16

显示和隐藏导航栏时更改 self.view.frame

change the self.view.frame when you are showing and hiding the navigation bars

只是我以为 2024-12-17 00:28:16
scrollView.contentInsetAdjustmentBehavior = .never
scrollView.contentInsetAdjustmentBehavior = .never
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文