0

我有一个显示图像缩略图的 UICollectionView。单击时,缩略图会调用另一个视图 ,wallpaperView以全尺寸显示图像。

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    // ...insert the usual row number check here

    UIViewController *wallpaperView = [QUOWallpaperViewController new];       
    [self.navigationController pushViewController:wallpaperView animated:YES];
}

(按照惯例,UICollectionView 本身是 UINavigationController 对象的根视图控制器)

现在,在 中wallpaperView,我想隐藏导航栏,并显示我自己的自定义按钮我已经在这里找到了解决方案

按照那里的最佳答案,我把这段代码放在wallpaperViewController.m

- (void)viewWillAppear:(BOOL)animated
{        
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}

但是,这不起作用。导航栏仍然照常显示。有谁知道为什么会这样?

4

3 回答 3

1

如果您需要在导航上将自己的按钮显示为栏按钮,则无需隐藏导航栏,我已经浏览了您的代码并进行了一些修改,只需使用此按钮,不要隐藏导航栏即可。

UIImage* image3 = [UIImage imageNamed:@"mail-48_24.png"]; 
CGRect frameimg = CGRectMake(0, 0, image3.size.width, image3.size.height); 
UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg]; 
[someButton setBackgroundImage:image3 forState:UIControlStateNormal]; 
[someButton addTarget:self action:@selector(sendmail) forControlEvents:UIControlEventTouchUpInside]; 
[someButton setShowsTouchWhenHighlighted:YES]; 

UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton]; 
self.navigationItem.rightBarButtonItem=mailbutton; 
[someButton release];

self.navigationController.navigationBar.translucent = YES; // Setting this slides the view up, underneath the nav bar (otherwise it'll appear black)
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];

[self.navigationController.navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];
//remove shadow
[[UINavigationBar appearance] setShadowImage: [[UIImage alloc] init]];
于 2013-09-12T06:19:28.817 回答
0

尝试隐藏导航控制器

在您的类 QUOWallpaperViewController 的 viewDidLoad 方法中

[self.navigationController setNavigationBarHidden:YES animated:YES];
于 2013-09-12T05:48:12.507 回答
0

您可以在 ViewDidLoad 方法中编写此代码。

self.navigationController.navigationBarHidden=YES;
于 2013-09-12T05:53:48.087 回答