Solve the problem of inexplicable horizontal line at the bottom of transparent Navigationbar

Source: Internet
Author: User

There is a page to implement the transparent Navigationbar, realized after the discovery of a strange problem: the first time to enter this page shows the transparent Navigationbar normal, return to the previous page and re-entry, navigationbar the bottom of a line of about 1px, How can not be eliminated.

Check this line with reveal, is a uiimageview,0.5px height, the first normal display when the center y coordinate is 63.75, so the display is normal; return to the previous page and re-enter, center The Y coordinate is 64.25 and appears exactly below the navigationbar without being overwritten by it.

Guess is because to achieve transparent navigationbar in which a 64px height overlay view affects the position of the horizontal line. Finally, the workaround is found in this article:

First–declare instance variable:

@implementation Myviewcontroller {Uiimageview *navbarhairlineimageview;}

Then, in do viewDidLoad :

Navbarhairlineimageview = [self findhairlineimageviewunder:navigationbar];

Method which finds the image view we need:

-(Uiimageview *) Findhairlineimageviewunder: (UIView *) View {if ([view IsKindOfClass:UIImageView.class] && view    . Bounds.size.height <= 1.0) {return (Uiimageview *) view;        } for (UIView *subview in view.subviews) {Uiimageview *imageview = [self findhairlineimageviewunder:subview];        if (ImageView) {return imageView; }} return nil;}

And this would do the rest of the magic:

-(void) Viewwillappear: (BOOL) animated {[Super viewwillappear:animated]; Navbarhairlineimageview.hidden = YES;}    -(void) Viewwilldisappear: (BOOL) animated {[Super viewwilldisappear:animated]; Navbarhairlineimageview.hidden = NO;}

Same method should also work for UISearchBar hairline.


Solve the problem of inexplicable horizontal line at the bottom of transparent Navigationbar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.