listenzz / HBDNavigationBar

A custom UINavigationBar for smooth switching between various states, including bar style, bar tint color, background image, background alpha, bar hidden, title text attributes, tint color, shadow hidden...
MIT License
1.65k stars 215 forks source link

iOS18适配,导航栏透底问题已修复 #188

Open xygkevin opened 1 month ago

cuizhiyuan commented 1 month ago

@listenzz 麻烦尽快适配一下iOS18

ctl0809 commented 1 month ago

iOS18 设置hbd_barAlpha=0.0 的页面 push 到下个页面会出现导航栏

Uploading ღ Monster .tu lin 2024-09-09 14.46.24.mp4…

透底情况,麻烦尽快适配 18 哦

xygkevin commented 1 month ago

BUG已定位并修复 @cuizhiyuan @ctl0809 @listenzz

问题定位:

UIView *back = self.navigationBar.subviews[0];

其本意应该是或取_UIBarBackground背景图层对象,但是更新iOS18之后,当我们使用导航控制进行push或者pop的时候会执行以下方法:

1、<_UIBarBackground: 0x10a2bf700> removeFromSuperview
2、UINavigationBar会执行-[insertSubview:<_UIBarBackground: 0x10a2bf700> atIndex:0]

问题方法正好在1和2之前执行,导致获取不到正确的_UIBarBackground对象,而是另外一个_UIPointerInteractionAssistantEffectContainerView对象,frame={0, 0, 0, 0};

问题截图:

image

解决办法:

image
ctl0809 commented 1 month ago

后面会更新版本吗?

xygkevin commented 1 month ago

不晓得作者是否还会继续维护,但我决定放弃使用它了,其实还有很多问题[捂脸],每次大更新都提心吊胆的。

cuizhiyuan commented 1 month ago

有好的替代框架吗?没有的话,我都改回原生算了

ctl0809 commented 1 month ago

同问,有好的替代框架吗?

xygkevin commented 1 month ago

木有

178408714 commented 1 month ago

改了 问题依然存在 😶

xygkevin commented 1 month ago

可以试试自己计算frame @178408714

178408714 commented 1 month ago

改成了 😄 [self.navigationBar setNeedsLayout]; [self.navigationBar layoutIfNeeded];

只能先这样了

Serakaterina commented 1 month ago

image 最好是在这个地方进行判断,如果发现frame为0,自己配置为状态栏的frame(如图中frame代码只是为了做测试使用)。 使用以下两句代码是有问题的: [self.navigationBar setNeedsLayout]; [self.navigationBar layoutIfNeeded]; 具体表现为:当A页面导航栏透明,黑色状态栏,B页面白色navigationTitle时,白色状态栏时,手势侧滑过程中,就会把navigationTitle颜色改为黑色了。

todayismancheng commented 1 month ago

在ios18上,当前hbd_barAlpha = 0 push的时候下一个导航栏显示不正常 playGestureRecognizer 2.zip

todayismancheng commented 1 month ago

@listenzz

xygkevin commented 1 month ago

暂且这么修改吧

- (CGRect)fakeBarFrameForViewController:(UIViewController *)vc {
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = 0;
    CGFloat h = 0;
    if (@available(iOS 13.0, *)) {
        UIWindowScene *windowScene = [UIApplication sharedApplication].connectedScenes.allObjects.firstObject;
        w = CGRectGetWidth(windowScene.statusBarManager.statusBarFrame);
        h = 44.0 + CGRectGetHeight(windowScene.statusBarManager.statusBarFrame);
    } else {
        w = CGRectGetWidth(UIApplication.sharedApplication.statusBarFrame);
        h = CGRectGetHeight(UIApplication.sharedApplication.statusBarFrame) + 44.0;
    }
    y = -h;
    return CGRectMake(x, y, w, h);
}
listenzz commented 1 month ago

暂且这么修改吧

- (CGRect)fakeBarFrameForViewController:(UIViewController *)vc {
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = 0;
    CGFloat h = 0;
    if (@available(iOS 13.0, *)) {
        UIWindowScene *windowScene = [UIApplication sharedApplication].connectedScenes.allObjects.firstObject;
        w = CGRectGetWidth(windowScene.statusBarManager.statusBarFrame);
        h = 44.0 + CGRectGetHeight(windowScene.statusBarManager.statusBarFrame);
    } else {
        w = CGRectGetWidth(UIApplication.sharedApplication.statusBarFrame);
        h = CGRectGetHeight(UIApplication.sharedApplication.statusBarFrame) + 44.0;
    }
    y = -h;
    return CGRectMake(x, y, w, h);
}

@todayismancheng 试下这个方案

todayismancheng commented 1 month ago

暂且这么修改吧

- (CGRect)fakeBarFrameForViewController:(UIViewController *)vc {
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = 0;
    CGFloat h = 0;
    if (@available(iOS 13.0, *)) {
        UIWindowScene *windowScene = [UIApplication sharedApplication].connectedScenes.allObjects.firstObject;
        w = CGRectGetWidth(windowScene.statusBarManager.statusBarFrame);
        h = 44.0 + CGRectGetHeight(windowScene.statusBarManager.statusBarFrame);
    } else {
        w = CGRectGetWidth(UIApplication.sharedApplication.statusBarFrame);
        h = CGRectGetHeight(UIApplication.sharedApplication.statusBarFrame) + 44.0;
    }
    y = -h;
    return CGRectMake(x, y, w, h);
}

@todayismancheng 试下这个方案

现在导航栏能正常显示了。 还有个问题是 导航栏的push pop 的时候 里面的内容会跳一下

xygkevin commented 1 month ago

@todayismancheng 我这里没发现闪动的问题,可以发个DEMO,录个屏看下问题原因

todayismancheng commented 1 month ago

https://github.com/user-attachments/assets/c72e365a-2f5c-4405-bba3-4f3d1ef3cb8f

我在demo上没复现,但是在app上是这个样子 @xygkevin

xygkevin commented 1 month ago

嗯嗯,那目前这个只能自己先慢慢排查问题原因了。

htyo commented 1 month ago

暂且这么修改吧

- (CGRect)fakeBarFrameForViewController:(UIViewController *)vc {
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = 0;
    CGFloat h = 0;
    if (@available(iOS 13.0, *)) {
        UIWindowScene *windowScene = [UIApplication sharedApplication].connectedScenes.allObjects.firstObject;
        w = CGRectGetWidth(windowScene.statusBarManager.statusBarFrame);
        h = 44.0 + CGRectGetHeight(windowScene.statusBarManager.statusBarFrame);
    } else {
        w = CGRectGetWidth(UIApplication.sharedApplication.statusBarFrame);
        h = CGRectGetHeight(UIApplication.sharedApplication.statusBarFrame) + 44.0;
    }
    y = -h;
    return CGRectMake(x, y, w, h);
}

@todayismancheng 试下这个方案

对我有用

xygkevin commented 5 hours ago

@listenzz @ctl0809 @cuizhiyuan @todayismancheng 最终修复版本可以试下这个PR