简体   繁体   中英

How to make UINavigationBar taller like in Mail.app

Apple Mail app in thread views has a dynamic, taller than usual navigation bar which collapses when you scroll. Is it possible to achieve same effect using only allowed API calls or is this available only internally for Apple?

Expanded: 邮件导航栏已展开

Collapsed: 邮件导航栏折叠

Please check here . The link has different ways to solve the problem. However following code helped me.

for subview in (self.navigationController?.navigationBar.subviews)! {
   if NSStringFromClass(subview.classForCoder).contains("BarBackground") {
        var subViewFrame: CGRect = subview.frame
        // subViewFrame.origin.y = -20;
        subViewFrame.size.height = 100
        subview.frame = subViewFrame

    }

}

You can able to set it as follows

-(void)layoutSubviews{
        [super layoutSubviews];
        CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
        if (rectStatus.size.height==44.f) {

        }else{
            if (@available(iOS 11.0, *)) {
                for ( UIView*aView in self.subviews) {
                    if ([NSStringFromClass(aView.classForCoder) isEqualToString:@"_UINavigationBarContentView"]) {
                        aView.frame = CGRectMake( 0,20,aView.frame.size.width,44);
                    }
                    else if ([NSStringFromClass(aView.classForCoder) isEqualToString:@"_UIBarBackground"]) {
                        aView.frame = CGRectMake(0,0,aView.frame.size.width, 64);
                    }
                }
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM