导航栏的横向模式问题

发布于 2024-10-03 01:51:38 字数 693 浏览 4 评论 0原文

我有一个 ViewController 来管理一个视图,其中有一个 Table View、一个 ImageView 和一个导航栏。 当我将其置于横向模式时,导航栏的大小不会调整为 32,它仍然保持为 44 我首先尝试在 IB 中使用自动调整大小但没有成功,然后我尝试将此代码放入 ViewController

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
    //[super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
    CGRect frame = self.navigationController.navigationBar.frame;
    if (UIInterfaceOrientationIsPortrait(orientation)) {
         frame.size.height = 44;
    } else {
         frame.size.height = 32;
    }
    self.navigationController.navigationBar.frame = frame;
}

但什么也没有。 我该如何解决这个问题?

I have a ViewController that manages a view in which I have a Table View, an ImageView and a Navigation Bar.
When I put it in the landscape mode the Navigation Bar doesn't resize to 32, it still remains to 44
I tried first to use the autosizing in IB without success, then I tried to put this code in the ViewController

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
    //[super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
    CGRect frame = self.navigationController.navigationBar.frame;
    if (UIInterfaceOrientationIsPortrait(orientation)) {
         frame.size.height = 44;
    } else {
         frame.size.height = 32;
    }
    self.navigationController.navigationBar.frame = frame;
}

but nothing.
How can I solve this issue?

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

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

发布评论

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

评论(2

咋地 2024-10-10 01:51:38

我犯了一个错误,没有navigationController,所以我将IB中的导航栏与代码中的outlet navBar链接起来,并且我已经使用

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation  duration:(NSTimeInterval)duration {
    [super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
    CGRect frame = self.navBar.frame;
    if (UIInterfaceOrientationIsPortrait(orientation)) {
        frame.size.height = 44;
    } else {
        frame.size.height = 32;
    }
    self.navBar.frame = frame;  
}

它现在可以工作了,我只有图像视图的问题

I made a mistake, there isn't a navigationController, so I linked the navigation bar in IB with the outlet navBar in the code and I've used

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation  duration:(NSTimeInterval)duration {
    [super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
    CGRect frame = self.navBar.frame;
    if (UIInterfaceOrientationIsPortrait(orientation)) {
        frame.size.height = 44;
    } else {
        frame.size.height = 32;
    }
    self.navBar.frame = frame;  
}

It works now, I've only a problem with the image view

快乐很简单 2024-10-10 01:51:38

我对导航顶部栏的自定义背景图像也有同样的问题。

我的横向图像的高度不正确,它是 44 像素高,而不是 32 像素(@2x 版本相同,它是 88 像素而不是 64)。裁剪图像后,横向顶部栏具有正确的高度。

I had the same problem with a customized background image for the navigation top bar.

My landscape image was not the correct height, it was 44px high instead of 32px (same for the @2x version, it was 88px instead of 64). After cropping the images, the landscape top bar has the correct height.

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