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