技术实现关键点:通过layer.shadowOpacity
和View.layer.shadowOffset
实现
原文地址
https://blog.csdn.net/z929118967/article/details/93181646
在这里插入图片描述
- (void)setupshadowColor{
UIView * tmpView = self;
tmpView.layer.shadowColor = [UIColor blackColor].CGColor;//设置阴影的颜色
tmpView.layer.shadowOpacity = 0.08;//设置阴影的透明度
tmpView.layer.shadowOffset = CGSizeMake(kAdjustRatio(0), kAdjustRatio(0));//设置阴影的偏移量,阴影的大小,x往右和y往下是正
tmpView.layer.shadowRadius = kAdjustRatio(5);//设置阴影的圆角,//阴影的扩散范围,相当于blur radius,也是shadow的渐变距离,从外围开始,往里渐变shadowRadius距离
//去掉TabBar的顶部黑线
[self setBackgroundImage:[UIImage createImageWithColor:[UIColor clearColor]]];
[self setShadowImage:[UIImage createImageWithColor:[UIColor clearColor]]];
}
在这里插入图片描述
在这里插入图片描述
@implementation QCTShadowView
- (instancetype)init
{
self = [super init];
if (self) {
[self setupshadowColor];
//
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
[self layoutIfNeeded];
[self.layer layoutIfNeeded];
[self setupshadowColor];
}
- (void) setupshadowColor{
UIView * tmpView = self;
tmpView.layer.shadowColor = [UIColor blackColor].CGColor;//设置阴影的颜色
tmpView.layer.shadowOpacity = 0.08;//设置阴影的透明度
tmpView.layer.shadowOffset = CGSizeMake(kAdjustRatio(0), kAdjustRatio(5));//设置阴影的偏移量,阴影的大小,x往右和y往下是正
tmpView.layer.shadowRadius = kAdjustRatio(5);//设置阴影的圆角,//阴影的扩散范围,相当于blur radius,也是shadow的渐变距离,从外围开始,往里渐变shadowRadius距离
}
[_vcView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.offset(0);
}];
[_vcView mas_makeConstraints:^(MASConstraintMaker *make) {
[tmp mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.view).offset(0);
make.right.equalTo(weakSelf.view).offset(- 0);
make.top.equalTo(weakSelf.view).offset(0);
make.bottom.equalTo(weakSelf.view).offset(-weakSelf.tabBarController.tabBar.bounds.size.height);//避免视图被TabBar挡住
}];
}];
https://blog.csdn.net/z929118967/article/details/104487015
// 适配iOS13导致的bug
if (@available(iOS 13.0, *)) {
// iOS 13以上
// self.tabBar.tintColor = ;
self.tabBar.unselectedItemTintColor = ktabNorTextColor;
self.tabBar.tintColor = ktabSelectedTextColor;
// self.tabBar.unselectedItemTintColor = ;
// UITabBarItem *item = [UITabBarItem appearance];
// item.titlePositionAdjustment = UIOffse/tMake(0, -2);
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateNormal];
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateSelected];
} else {
// // iOS 13以下
// UITabBarItem *item = [UITabBarItem appearance];
// item.titlePositionAdjustment = UIOffsetMake(0, -2);
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:RGB_HEX(0x999999)} forState:UIControlStateNormal];
// [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:RGB_HEX(0xfb5400)} forState:UIControlStateSelected];
//设置文字样式
NSMutableDictionary *textAttr = [NSMutableDictionary dictionary];
textAttr[NSForegroundColorAttributeName] = ktabNorTextColor;
[childVC.tabBarItem setTitleTextAttributes:textAttr forState:UIControlStateNormal];
//选择状态的文字颜色样式
NSMutableDictionary *selectedTextAttr = [NSMutableDictionary dictionary];
[selectedTextAttr setValue:ktabSelectedTextColor forKey:NSForegroundColorAttributeName];
[childVC.tabBarItem setTitleTextAttributes:selectedTextAttr forState:UIControlStateSelected];
}
若项目有全局的UINavigationController基类,给页面添加右滑返回手势
@implementation NavigationController
- (void)viewDidLoad
{
[super viewDidLoad];
//设置右滑返回手势的代理为自身
__weak typeof(self) weakself = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = (id)weakself;
}
}
#pragma mark - UIGestureRecognizerDelegate
//这个方法是在手势将要激活前调用:返回YES允许右滑手势的激活,返回NO不允许右滑手势的激活
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer == self.interactivePopGestureRecognizer) {
//屏蔽调用rootViewController的滑动返回手势,避免右滑返回手势引起死机问题
if (self.viewControllers.count < 2 ||
self.visibleViewController == [self.viewControllers objectAtIndex:0]) {
return NO;
}
}
//这里就是非右滑手势调用的方法啦,统一允许激活
return YES;
}