第一种:
先设置一个全局变量 UIImageView * imageView;
然后:
- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; _imageView.hidden = YES;}- (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; _imageView.hidden = NO;}- (void)viewDidLoad { [super viewDidLoad]; _imageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];}- (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;}
第二种:
直接在AppDelegate.m中设置,可全局生效
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];