隐藏导航栏横线
1 | @interface ViewController () |
Storyboard勾选Hide-Bottom-Bar-on-Push带来黑影问题
去掉”Hide Bottom Bar on Push”前面的勾,在相应的控制器中使用代码来实现tabbar的显示和隐藏,即分别在viewWillAppear和viewWillDisappear方法中实现所需要的效果。
判定viewWillDisappear是push还是pop
1 | if ([self.navigationController.viewControllers indexOfObject:self] == NSNotFound) { |
自定义导航栏返回箭头导致返回手势失效
在自定义导航控制器viewDidLoad
方法中加入如下代码:1
self.interactivePopGestureRecognizer.delegate = (id)self;
自定义导航栏为渐变色
在自定义导航控制器中设置:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
- (void)viewDidLoad {
[super viewDidLoad];
[self setBarBackgroundColor];
}
- (void)setBarBackgroundColor {
for (UIView *view in self.navigationBar.subviews) {
if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")] || [view isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) {
NSString *phoneVersion = [[UIDevice currentDevice] systemVersion];
UIView *iView = nil;
if (phoneVersion.floatValue < 10.0) {
iView = view;
} else {
for (UIView *subView in view.subviews) {
if ([subView isKindOfClass:[UIVisualEffectView class]]) {
iView = subView;
}
}
}
CRLog(@"it is");
CGRect frame = iView.frame;
CRLog(@"%@", NSStringFromCGRect(frame));
UIView *alphaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height + 20)];
alphaView.backgroundColor = [UIColor whiteColor];
alphaView.userInteractionEnabled = NO;
[iView addSubview:alphaView];
[self setShadeColorWithView:alphaView];
}
}
}
- (void)setShadeColorWithView:(UIView *)view {
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.startPoint = CGPointMake(0, .5);
gradientLayer.endPoint = CGPointMake(1, .5);
gradientLayer.colors = @[(id)RGBA(76, 202, 90, 1).CGColor,(id)RGBA(39, 182, 112, 1).CGColor];
gradientLayer.frame = view.bounds;
[view.layer addSublayer:gradientLayer];
}
全局设置导航控制器返回按钮
在自定义导航控制器中做如下拦截处理:1
2
3
4
5
6
7
8
9
10
11
12- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
UIImage *image = [[UIImage imageNamed:@"backButton_background"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleDone target:self action:@selector(back)];
[super pushViewController:viewController animated:animated];
}
- (void)back {
[self popViewControllerAnimated:YES];
}
通过Scheme区分管理Debug和Release环境
- 1、 新建两个Scheme,分别为
projectName-Debug
和projectName-Release
,编辑对应的Scheme,将Build Configuration
分别改为 Debug 和 Release。 - 2、 在PCH文件中添加如下宏定义:
1
2
3
4
5ifdef DEBUG
define kServer @"http://192.168.0.1:8080"
else
define kServer @"http://xxoo.com"
endif
Sample code:demo/Debug&Release-Demo
PCH常用宏定义
1 | define RGBA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a] |