This commit is contained in:
2025-11-06 21:38:58 +08:00
parent 0d13192723
commit 0fa3d10284
15 changed files with 300 additions and 20 deletions

View File

@@ -21,6 +21,8 @@
0477BE042EBC83130055D639 /* HomeMainVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0477BE032EBC83130055D639 /* HomeMainVC.m */; };
047C650D2EBC8A840035E841 /* KBPanModalView.m in Sources */ = {isa = PBXBuildFile; fileRef = 047C650C2EBC8A840035E841 /* KBPanModalView.m */; };
047C65102EBCA8DD0035E841 /* HomeRankContentVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 047C650F2EBCA8DD0035E841 /* HomeRankContentVC.m */; };
047C655C2EBCD0F80035E841 /* UIView+KBShadow.m in Sources */ = {isa = PBXBuildFile; fileRef = 047C655B2EBCD08E0035E841 /* UIView+KBShadow.m */; };
047C655E2EBCD5B20035E841 /* UIImage+KBColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 047C655D2EBCD5B20035E841 /* UIImage+KBColor.m */; };
047C652D2EBCAAAC0035E841 /* crab_selected.png in Resources */ = {isa = PBXBuildFile; fileRef = 047C651F2EBCAAAC0035E841 /* crab_selected.png */; };
047C652E2EBCAAAC0035E841 /* crab.png in Resources */ = {isa = PBXBuildFile; fileRef = 047C651E2EBCAAAC0035E841 /* crab.png */; };
047C652F2EBCAAAC0035E841 /* arrow_down.png in Resources */ = {isa = PBXBuildFile; fileRef = 047C651A2EBCAAAC0035E841 /* arrow_down.png */; };
@@ -185,6 +187,10 @@
047C65522EBCBAC60035E841 /* KBCommunityVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBCommunityVC.m; sourceTree = "<group>"; };
047C65562EBCC06D0035E841 /* HomeRankCardCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeRankCardCell.h; sourceTree = "<group>"; };
047C65572EBCC06D0035E841 /* HomeRankCardCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeRankCardCell.m; sourceTree = "<group>"; };
047C655A2EBCD08E0035E841 /* UIView+KBShadow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIView+KBShadow.h"; sourceTree = "<group>"; };
047C655B2EBCD08E0035E841 /* UIView+KBShadow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIView+KBShadow.m"; sourceTree = "<group>"; };
047C655C2EBCD5B20035E841 /* UIImage+KBColor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIImage+KBColor.h"; sourceTree = "<group>"; };
047C655D2EBCD5B20035E841 /* UIImage+KBColor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIImage+KBColor.m"; sourceTree = "<group>"; };
04A9A67D2EB9E1690023B8F4 /* KBResponderUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBResponderUtils.h; sourceTree = "<group>"; };
04A9FE102EB4D0D20020DB6D /* KBFullAccessManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBFullAccessManager.h; sourceTree = "<group>"; };
04A9FE112EB4D0D20020DB6D /* KBFullAccessManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBFullAccessManager.m; sourceTree = "<group>"; };
@@ -777,6 +783,10 @@
04FC97082EB31B14007BD342 /* KBHUD.m */,
04A9FE142EB873C80020DB6D /* UIViewController+Extension.h */,
04A9FE152EB873C80020DB6D /* UIViewController+Extension.m */,
047C655A2EBCD08E0035E841 /* UIView+KBShadow.h */,
047C655B2EBCD08E0035E841 /* UIView+KBShadow.m */,
047C655C2EBCD5B20035E841 /* UIImage+KBColor.h */,
047C655D2EBCD5B20035E841 /* UIImage+KBColor.m */,
);
path = Categories;
sourceTree = "<group>";
@@ -1146,6 +1156,8 @@
0477BDF72EBC63A80055D639 /* KBTestVC.m in Sources */,
04FC95C92EB1E4C9007BD342 /* BaseNavigationController.m in Sources */,
047C65102EBCA8DD0035E841 /* HomeRankContentVC.m in Sources */,
047C655C2EBCD0F80035E841 /* UIView+KBShadow.m in Sources */,
047C655E2EBCD5B20035E841 /* UIImage+KBColor.m in Sources */,
04FC95DD2EB202A3007BD342 /* KBGuideVC.m in Sources */,
04FC95E52EB220B5007BD342 /* UIColor+Extension.m in Sources */,
0477BDF02EBB76E30055D639 /* HomeSheetVC.m in Sources */,

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "home_bg_image 1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "home_bg_image 2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 KiB

View File

@@ -0,0 +1,42 @@
//
// UIImage+KBColor.h
// keyBoard
//
// 颜色/渐变 生成图片工具
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, KBGradientDirection) {
KBGradientDirectionLeftToRight = 0, // 左 → 右
KBGradientDirectionTopToBottom, // 上 → 下
KBGradientDirectionLeftTopToRightBottom,// 左上 → 右下
KBGradientDirectionLeftBottomToRightTop // 左下 → 右上
};
@interface UIImage (KBColor)
/// 用纯色生成图片
+ (UIImage *)kb_imageWithColor:(UIColor *)color size:(CGSize)size;
/// 用纯色生成圆角图片
+ (UIImage *)kb_imageWithColor:(UIColor *)color size:(CGSize)size cornerRadius:(CGFloat)cornerRadius;
/// 生成渐变图片(默认均匀分布)
+ (UIImage *)kb_gradientImageWithColors:(NSArray<UIColor *> *)colors
size:(CGSize)size
direction:(KBGradientDirection)direction;
/// 生成渐变图片(可指定 locations 与圆角)
+ (UIImage *)kb_gradientImageWithColors:(NSArray<UIColor *> *)colors
locations:(NSArray<NSNumber *> * _Nullable)locations
size:(CGSize)size
direction:(KBGradientDirection)direction
cornerRadius:(CGFloat)cornerRadius;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,86 @@
//
// UIImage+KBColor.m
// keyBoard
//
// /
//
#import "UIImage+KBColor.h"
@implementation UIImage (KBColor)
+ (UIImage *)kb_imageWithColor:(UIColor *)color size:(CGSize)size {
return [self kb_imageWithColor:color size:size cornerRadius:0];
}
+ (UIImage *)kb_imageWithColor:(UIColor *)color size:(CGSize)size cornerRadius:(CGFloat)cornerRadius {
if (size.width <= 0 || size.height <= 0 || !color) { return nil; }
CGRect rect = (CGRect){CGPointZero, size};
UIGraphicsBeginImageContextWithOptions(size, NO, 0); // 0 => 使 scale
CGContextRef ctx = UIGraphicsGetCurrentContext();
if (cornerRadius > 0) {
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius];
[path addClip];
}
CGContextSetFillColorWithColor(ctx, color.CGColor);
CGContextFillRect(ctx, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
+ (UIImage *)kb_gradientImageWithColors:(NSArray<UIColor *> *)colors
size:(CGSize)size
direction:(KBGradientDirection)direction {
return [self kb_gradientImageWithColors:colors locations:nil size:size direction:direction cornerRadius:0];
}
+ (UIImage *)kb_gradientImageWithColors:(NSArray<UIColor *> *)colors
locations:(NSArray<NSNumber *> * _Nullable)locations
size:(CGSize)size
direction:(KBGradientDirection)direction
cornerRadius:(CGFloat)cornerRadius {
if (colors.count == 0 || size.width <= 0 || size.height <= 0) { return nil; }
//
CAGradientLayer *layer = [CAGradientLayer layer];
layer.frame = (CGRect){CGPointZero, size};
NSMutableArray *cgColors = [NSMutableArray arrayWithCapacity:colors.count];
for (UIColor *c in colors) { [cgColors addObject:(id)c.CGColor]; }
layer.colors = cgColors;
if (locations.count == colors.count) { layer.locations = locations; }
// ->
switch (direction) {
case KBGradientDirectionLeftToRight:
layer.startPoint = CGPointMake(0, 0.5);
layer.endPoint = CGPointMake(1, 0.5);
break;
case KBGradientDirectionTopToBottom:
layer.startPoint = CGPointMake(0.5, 0);
layer.endPoint = CGPointMake(0.5, 1);
break;
case KBGradientDirectionLeftTopToRightBottom:
layer.startPoint = CGPointMake(0, 0);
layer.endPoint = CGPointMake(1, 1);
break;
case KBGradientDirectionLeftBottomToRightTop:
layer.startPoint = CGPointMake(0, 1);
layer.endPoint = CGPointMake(1, 0);
break;
}
if (cornerRadius > 0) {
layer.cornerRadius = cornerRadius;
layer.masksToBounds = YES;
}
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[layer renderInContext:ctx];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
@end

View File

@@ -0,0 +1,34 @@
//
// UIView+KBShadow.h
// keyBoard
//
// 基础阴影封装:一行设置卡片阴影,支持圆角与路径缓存
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIView (KBShadow)
/// 便捷方法设置卡片阴影常用黑色、透明度0.15、半径10、偏移(0,6))并记录圆角和内边距,用于后续更新路径
- (void)kb_setCardShadowWithCornerRadius:(CGFloat)cornerRadius insets:(UIEdgeInsets)insets;
/// 自定义阴影参数;同时记录 cornerRadius 与 insets供 `kb_updateShadowPath` 使用
- (void)kb_setShadowWithColor:(UIColor *)color
opacity:(float)opacity
radius:(CGFloat)radius
offset:(CGSize)offset
cornerRadius:(CGFloat)cornerRadius
insets:(UIEdgeInsets)insets;
/// 在 `layoutSubviews` 等尺寸变化后调用,按记录的 cornerRadius 与 insets 更新 shadowPath
- (void)kb_updateShadowPath;
/// 移除阴影(清理 shadowPath
- (void)kb_removeShadow;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,65 @@
//
// UIView+KBShadow.m
// keyBoard
//
//
#import "UIView+KBShadow.h"
#import <objc/runtime.h>
static const void *kKBShadowInsetsKey = &kKBShadowInsetsKey;
static const void *kKBShadowCornerRadiusKey = &kKBShadowCornerRadiusKey;
@implementation UIView (KBShadow)
- (void)kb_setCardShadowWithCornerRadius:(CGFloat)cornerRadius insets:(UIEdgeInsets)insets {
[self kb_setShadowWithColor:[UIColor blackColor]
opacity:0.15f
radius:10.0
offset:CGSizeMake(0, 6)
cornerRadius:cornerRadius
insets:insets];
}
- (void)kb_setShadowWithColor:(UIColor *)color
opacity:(float)opacity
radius:(CGFloat)radius
offset:(CGSize)offset
cornerRadius:(CGFloat)cornerRadius
insets:(UIEdgeInsets)insets {
CALayer *layer = self.layer;
layer.masksToBounds = NO; //
layer.shadowColor = color.CGColor;
layer.shadowOpacity = opacity;
layer.shadowRadius = radius;
layer.shadowOffset = offset;
//
objc_setAssociatedObject(self, kKBShadowInsetsKey, [NSValue valueWithUIEdgeInsets:insets], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, kKBShadowCornerRadiusKey, @(cornerRadius), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
// layout
[self kb_updateShadowPath];
}
- (void)kb_updateShadowPath {
NSValue *insetsVal = objc_getAssociatedObject(self, kKBShadowInsetsKey);
NSNumber *cornerVal = objc_getAssociatedObject(self, kKBShadowCornerRadiusKey);
if (!insetsVal || !cornerVal) return;
UIEdgeInsets insets = [insetsVal UIEdgeInsetsValue];
CGFloat corner = (CGFloat)[cornerVal doubleValue];
CGRect rect = UIEdgeInsetsInsetRect(self.bounds, insets);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:corner];
self.layer.shadowPath = path.CGPath;
}
- (void)kb_removeShadow {
CALayer *layer = self.layer;
layer.shadowOpacity = 0;
layer.shadowPath = nil;
objc_setAssociatedObject(self, kKBShadowInsetsKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, kKBShadowCornerRadiusKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end

View File

@@ -11,7 +11,7 @@
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor blueColor];
self.backgroundColor = [UIColor clearColor];
}
return self;
}

View File

@@ -7,6 +7,7 @@
@import UIKit;
#import "HomeRankCardCell.h"
#import "UIView+KBShadow.h"
@interface HomeRankCardCell ()
@property (nonatomic, strong) UIView *shadowView; //
@@ -39,6 +40,9 @@
[self.cardView addSubview:self.descLabel];
[self.cardView addSubview:self.peopleLabel];
[self.cardView addSubview:self.actionBtn];
// 8pt
[self.shadowView kb_setCardShadowWithCornerRadius:18.0 insets:UIEdgeInsetsMake(0, 8, 0, 8)];
}
- (void)setupConstraints {
@@ -86,13 +90,8 @@
- (void)layoutSubviews {
[super layoutSubviews];
//
_shadowView.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.15].CGColor;
_shadowView.layer.shadowOpacity = 1.0;
_shadowView.layer.shadowRadius = 10.0;
_shadowView.layer.shadowOffset = CGSizeMake(0, 6);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:_cardView.bounds cornerRadius:18.0];
_shadowView.layer.shadowPath = path.CGPath;
//
[self.shadowView kb_updateShadowPath];
_badgeCircle.layer.cornerRadius = 34;
}

View File

@@ -30,11 +30,10 @@
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor redColor];
HWBackgroundConfig *config = [HWBackgroundConfig configWithBehavior:HWBackgroundBehaviorDefault];
config = [HWBackgroundConfig configWithBehavior:HWBackgroundBehaviorDefault];
config.backgroundAlpha = 0.01;
[self.hw_dimmedView reloadConfig:config];
// self.backgroundColor = [UIColor redColor];
// HWBackgroundConfig *config = [HWBackgroundConfig configWithBehavior:HWBackgroundBehaviorDefault];
// config.backgroundAlpha = 0;
// [self.hw_dimmedView reloadConfig:config];
// +
[self setupTopButtonsAndContainer];
//

View File

@@ -11,6 +11,7 @@
@interface HomeMainVC ()
@property (nonatomic, strong) HomeHeadView *headView;
@property (nonatomic, strong) KBPanModalView *simplePanModalView;
@end
@@ -19,22 +20,32 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor];
// self.view.backgroundColor = [UIColor yellowColor];
UIImage *bgImage = [UIImage kb_gradientImageWithColors:@[[UIColor colorWithHex:0xE8FFF1], [UIColor colorWithHex:0xD4FDFF]] size:CGSizeMake(KB_SCREEN_WIDTH, KB_SCREEN_HEIGHT) direction:KBGradientDirectionTopToBottom];
UIImageView *bgImageView = [[UIImageView alloc] init];
bgImageView.image = bgImage;
[self.view addSubview:bgImageView];
[bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
CGFloat topV = (500);
// [self.view addSubview:self.headView];
// [self setupMas:topV];
// sheetVC
KBPanModalView *simplePanModalView = [[KBPanModalView alloc] init];
self.simplePanModalView = [[KBPanModalView alloc] init];
// 使 true
if (KB_DEVICE_HAS_NOTCH) {
simplePanModalView.minHeight = KB_SCREEN_HEIGHT - topV - 34;
self.simplePanModalView.minHeight = KB_SCREEN_HEIGHT - topV - 34;
}else{
simplePanModalView.minHeight = KB_SCREEN_HEIGHT - topV;
self.simplePanModalView.minHeight = KB_SCREEN_HEIGHT - topV;
//
}
simplePanModalView.topInset = 100;
[simplePanModalView presentInView:self.view];
self.simplePanModalView.topInset = 100;
[self.simplePanModalView presentInView:self.view];
HWBackgroundConfig *config = [HWBackgroundConfig configWithBehavior:HWBackgroundBehaviorDefault];
config.backgroundAlpha = 0;
[self.simplePanModalView.hw_dimmedView reloadConfig:config];
}
- (void)setupMas:(CGFloat)headViewTopV{

View File

@@ -35,7 +35,7 @@
self.view.backgroundColor = [UIColor redColor];
HWBackgroundConfig *config = [HWBackgroundConfig configWithBehavior:HWBackgroundBehaviorDefault];
config = [HWBackgroundConfig configWithBehavior:HWBackgroundBehaviorDefault];
config.backgroundAlpha = 0.01;
config.backgroundAlpha = 0.001;
[self.hw_dimmedView reloadConfig:config];
// +

View File

@@ -25,6 +25,10 @@
/// 项目
#import "UIView+KBShadow.h"
#import "UIImage+KBColor.h"
#import "UIColor+Extension.h"
#import "UIViewController+Extension.h"
#import "BaseNavigationController.h"
#import "BaseTableView.h"