1

我看过这个答案

https://stackoverflow.com/a/9243472/563381

尽管在导航栏的图层上设置蒙版后它的视觉效果很好,但它不再响应触摸......因此无法单击栏上出现的后退按钮。有什么解决方案可以让触摸通过 CALAyer?我不认为 CALayer 会阻止触摸或面具会阻止触摸。

4

2 回答 2

1

好吧,我真的不知道为什么 CALayer 会阻止触摸,这对我来说听起来很奇怪......

我将 UINavigationBar 转角的方式包括将 2 个 UIImageView(10x10 像素)放在角落并向它们添加 2 个图像。这些图像用作遮罩,不会阻挡触摸。如果您使用抗锯齿来绘制图像,则外观非常完美。

在此处输入图像描述

于 2012-04-05T16:40:43.700 回答
0

您应该尝试使用以下代码:

self.navigationController.navigationBar.translucent = YES;

这将打开你的后退按钮。你可以看到你的按钮,但它在另一层。这就是为什么它不会起作用的原因..

更新:

使用这行代码进行测试。这对你来说就像一个魅力。

//Style UINavigationBar
UIView *background = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
background.backgroundColor = [UIColor blackColor];
[self.view addSubview:background];
self.navigationController.navigationBar.tintColor = [UIColor cyanColor];
self.navigationController.navigationBar.translucent = YES;
CALayer *capa = [self.navigationController navigationBar].layer;
[capa setShadowColor: [[UIColor blackColor] CGColor]];
[capa setShadowOpacity:0.85f];
[capa setShadowOffset: CGSizeMake(0.0f, 1.5f)];
[capa setShadowRadius:2.0f];  
[capa setShouldRasterize:YES];

//Round
CGRect bounds = capa.bounds;
bounds.size.height += 10.0f;    //I'm reserving enough room for the shadow
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds 
                                               byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                                     cornerRadii:CGSizeMake(10.0, 10.0)];

CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = bounds;
maskLayer.path = maskPath.CGPath;

[capa addSublayer:maskLayer];
capa.mask = maskLayer;

//Back Btn
UIButton *btnback = [UIButton buttonWithType:UIButtonTypeCustom];
[btnback setFrame:CGRectMake(0, 0, 54, 29)];
[btnback setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
UILabel * btnlabel =  [[UILabel alloc]initWithFrame:CGRectMake(15, 0, 40, 23)];
btnlabel.backgroundColor = [UIColor clearColor];
btnlabel.textColor = [UIColor whiteColor];
btnlabel.font = [UIFont boldSystemFontOfSize:13];
btnlabel.text = @"back";
[btnback addSubview:btnlabel];
[btnback addTarget:self action:@selector(backHome:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btnback];
于 2013-03-07T16:01:37.703 回答