iOS11 UINavigationBar类问题

iOS 11 UINavigationBar category issue

当我覆盖 UINavigationbar 的 layoutSubviews 时,所有子视图都被删除。我正在尝试设置自定义导航栏高度。它工作正常,但出现故障 iOS 11。这是一个自定义类别。

我已经使用 setFrame: 和 layoutSubviews 方法创建了 UINavigationBar 的子类。 Storyboard中需要设置子类为NavigationController的NavigationBar。

CGFloat const NavBarHeight = 88.0;

- (CGSize)sizeThatFits:(CGSize)size {
    return [self getNavBarSize];
}

- (void)setFrame:(CGRect)frame {
    frame.size.height = NavBarHeight;

    for (UIView *subview in self.subviews) {
        if ([NSStringFromClass([subview class])  containsString:@"UINavigationBarContentView"]) {
            subview.frame = CGRectMake(0, 20, self.frame.size.width, NavBarHeight-30);
        }
        [subview sizeToFit];
    }
    [super setFrame:frame];

}

- (void)layoutSubviews {
    [super layoutSubviews];
    for (UIView *subview in self.subviews) {
        if ([NSStringFromClass([subview class]) containsString:@"BarBackground"]) {
            subview.frame = CGRectMake(0, -20, self.frame.size.width, NavBarHeight+20);
            [subview sizeToFit];
        }else if ([NSStringFromClass([subview class])  containsString:@"UINavigationBarContentView"]) {
            subview.frame = CGRectMake(0, 20, self.frame.size.width, NavBarHeight-30);
        }
    }
}