我已经看到了这个答案
https://stackoverflow.com/a/9243472/563381
虽然只要在导航栏的图层上设置遮罩就能很好地显示它,但它不再响应触摸......因此无法单击条上显示的后退按钮。任何导致触摸通过CALAyer的解决方案?我并不认为CALayer会受阻,或者面具会阻挡触摸。
答案 0 :(得分:1)
好吧,我真的不知道为什么CALayer阻止触摸,这对我来说听起来很奇怪......
我绕过UINavigationBar的角落的方法是在角落放置2个UIImageView(10x10像素)并为它们添加2个图像。这些图像作为蒙版工作,不会阻挡触摸。如果使用抗锯齿来绘制图像,则外观非常完美。
答案 1 :(得分: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];