This commit is contained in:
2025-11-14 14:07:04 +08:00
parent d164514fcf
commit eacac8425c
9 changed files with 392 additions and 10 deletions

View File

@@ -15,6 +15,10 @@
04122F702EC5F40800EF7AB3 /* FGIAPService.m in Sources */ = {isa = PBXBuildFile; fileRef = 04122F672EC5F40800EF7AB3 /* FGIAPService.m */; };
04122F7E2EC5FC5500EF7AB3 /* KBJfPayCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 04122F7C2EC5FC5500EF7AB3 /* KBJfPayCell.m */; };
04122F822EC5FC6F00EF7AB3 /* KBJfPay.m in Sources */ = {isa = PBXBuildFile; fileRef = 04122F802EC5FC6F00EF7AB3 /* KBJfPay.m */; };
04122F872EC6198C00EF7AB3 /* WMDragView.m in Sources */ = {isa = PBXBuildFile; fileRef = 04122F852EC6198C00EF7AB3 /* WMDragView.m */; };
04122F882EC6F07F00EF7AB3 /* KBFullAccessManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 04A9FE112EB4D0D20020DB6D /* KBFullAccessManager.m */; };
04122F8B2EC6F7C800EF7AB3 /* IAPVerifyTransactionObj.m in Sources */ = {isa = PBXBuildFile; fileRef = 04122F8A2EC6F7C800EF7AB3 /* IAPVerifyTransactionObj.m */; };
04122F8E2EC6F83F00EF7AB3 /* PayVM.m in Sources */ = {isa = PBXBuildFile; fileRef = 04122F8D2EC6F83F00EF7AB3 /* PayVM.m */; };
043FBCD22EAF97630036AFE1 /* KBPermissionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04C6EAE12EAF940F0089C901 /* KBPermissionViewController.m */; };
0459D1B42EBA284C00F2D189 /* KBSkinCenterVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 0459D1B32EBA284C00F2D189 /* KBSkinCenterVC.m */; };
0459D1B72EBA287900F2D189 /* KBSkinManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0459D1B62EBA287900F2D189 /* KBSkinManager.m */; };
@@ -203,6 +207,12 @@
04122F7C2EC5FC5500EF7AB3 /* KBJfPayCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBJfPayCell.m; sourceTree = "<group>"; };
04122F7F2EC5FC6F00EF7AB3 /* KBJfPay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBJfPay.h; sourceTree = "<group>"; };
04122F802EC5FC6F00EF7AB3 /* KBJfPay.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBJfPay.m; sourceTree = "<group>"; };
04122F842EC6198C00EF7AB3 /* WMDragView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WMDragView.h; sourceTree = "<group>"; };
04122F852EC6198C00EF7AB3 /* WMDragView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WMDragView.m; sourceTree = "<group>"; };
04122F892EC6F7C800EF7AB3 /* IAPVerifyTransactionObj.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IAPVerifyTransactionObj.h; sourceTree = "<group>"; };
04122F8A2EC6F7C800EF7AB3 /* IAPVerifyTransactionObj.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IAPVerifyTransactionObj.m; sourceTree = "<group>"; };
04122F8C2EC6F83F00EF7AB3 /* PayVM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PayVM.h; sourceTree = "<group>"; };
04122F8D2EC6F83F00EF7AB3 /* PayVM.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PayVM.m; sourceTree = "<group>"; };
0459D1B22EBA284C00F2D189 /* KBSkinCenterVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBSkinCenterVC.h; sourceTree = "<group>"; };
0459D1B32EBA284C00F2D189 /* KBSkinCenterVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBSkinCenterVC.m; sourceTree = "<group>"; };
0459D1B52EBA287900F2D189 /* KBSkinManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBSkinManager.h; sourceTree = "<group>"; };
@@ -502,6 +512,8 @@
04122F642EC5F40600EF7AB3 /* M */ = {
isa = PBXGroup;
children = (
04122F892EC6F7C800EF7AB3 /* IAPVerifyTransactionObj.h */,
04122F8A2EC6F7C800EF7AB3 /* IAPVerifyTransactionObj.m */,
);
path = M;
sourceTree = "<group>";
@@ -509,6 +521,8 @@
04122F652EC5F40600EF7AB3 /* VM */ = {
isa = PBXGroup;
children = (
04122F8C2EC6F83F00EF7AB3 /* PayVM.h */,
04122F8D2EC6F83F00EF7AB3 /* PayVM.m */,
);
path = VM;
sourceTree = "<group>";
@@ -548,6 +562,15 @@
path = VC;
sourceTree = "<group>";
};
04122F862EC6198C00EF7AB3 /* WMDragView */ = {
isa = PBXGroup;
children = (
04122F842EC6198C00EF7AB3 /* WMDragView.h */,
04122F852EC6198C00EF7AB3 /* WMDragView.m */,
);
path = WMDragView;
sourceTree = "<group>";
};
0477BD942EBAFF4E0055D639 /* Utils */ = {
isa = PBXGroup;
children = (
@@ -763,6 +786,7 @@
048908D32EBF618E00FABA60 /* Vender */ = {
isa = PBXGroup;
children = (
04122F862EC6198C00EF7AB3 /* WMDragView */,
04122F6C2EC5F40800EF7AB3 /* FGIAPService */,
049FB2162EC20A6600FAB05D /* BMLongPressDragCellCollectionView */,
048908D92EBF61AF00FABA60 /* UICollectionViewLeftAlignedLayout */,
@@ -1559,7 +1583,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
04122F882EC6F07F00EF7AB3 /* KBFullAccessManager.m in Sources */,
04122F622EC5F41D00EF7AB3 /* KBUser.m in Sources */,
04122F8B2EC6F7C800EF7AB3 /* IAPVerifyTransactionObj.m in Sources */,
049FB31D2EC21BCD00FAB05D /* KBMyKeyboardCell.m in Sources */,
048909F62EC0AAAA00FABA60 /* KBCategoryTitleCell.m in Sources */,
048909F72EC0AAAA00FABA60 /* KBCategoryTitleView.m in Sources */,
@@ -1605,6 +1631,7 @@
049FB2292EC31BB000FAB05D /* KBChangeNicknamePopView.m in Sources */,
048908EC2EBF849300FABA60 /* KBSkinTagsContainerCell.m in Sources */,
049FB2172EC20A6600FAB05D /* BMLongPressDragCellCollectionView.m in Sources */,
04122F8E2EC6F83F00EF7AB3 /* PayVM.m in Sources */,
0477BDF02EBB76E30055D639 /* HomeSheetVC.m in Sources */,
048908E62EBF841B00FABA60 /* KBSkinDetailTagCell.m in Sources */,
04FC97002EB30A00007BD342 /* KBGuideTopCell.m in Sources */,
@@ -1631,6 +1658,7 @@
0477BDFD2EBC6A170055D639 /* HomeHotVC.m in Sources */,
049FB2432EC4BBB700FAB05D /* KBLoginPopView.m in Sources */,
048908CC2EBE373500FABA60 /* KBSearchBarView.m in Sources */,
04122F872EC6198C00EF7AB3 /* WMDragView.m in Sources */,
048908CD2EBE373500FABA60 /* KBSearchSectionHeader.m in Sources */,
049FB2202EC30D2700FAB05D /* HomeRankDetailPopView.m in Sources */,
048908CE2EBE373500FABA60 /* KBSkinCardCell.m in Sources */,

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -9,11 +9,14 @@
#import "HomeHeadView.h"
#import "KBPanModalView.h"
#import "KBGuideVC.h" //
#import "WMDragView.h"
@interface HomeMainVC ()
@property (nonatomic, strong) HomeHeadView *headView;
@property (nonatomic, strong) KBPanModalView *simplePanModalView;
///
@property (nonatomic, strong) WMDragView *keyPermissButton;
@end
@implementation HomeMainVC
@@ -27,8 +30,6 @@
[bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
// CGFloat topV = (500);
[self.view addSubview:self.headView];
[self setupMas];
// sheetVC
@@ -42,6 +43,14 @@
}
self.simplePanModalView.topInset = 100;
[self.simplePanModalView presentInView:self.view];
[self.view addSubview:self.keyPermissButton];
self.keyPermissButton.frame = CGRectMake(KB_SCREEN_WIDTH - 92, KB_SCREEN_HEIGHT - 78 - 120, 92, 78);
KBWeakSelf
self.keyPermissButton.clickDragViewBlock = ^(WMDragView *dragView){
KBGuideVC *vc = [KBGuideVC new];
[weakSelf.navigationController pushViewController:vc animated:true];
};
}
// viewDidLoad push
@@ -87,4 +96,15 @@
}
- (WMDragView *)keyPermissButton{
if (!_keyPermissButton) {
_keyPermissButton = [[WMDragView alloc] init];
_keyPermissButton.backgroundColor = [UIColor clearColor];
_keyPermissButton.isKeepBounds = true;
[_keyPermissButton.button setImage:[UIImage imageNamed:@"key_permiss_icon"] forState:UIControlStateNormal];
}
return _keyPermissButton;
}
@end

View File

@@ -42,8 +42,8 @@
__weak typeof(self) weakSelf = self;
[self.payVM applePayReqWithParams:params needShow:NO completion:^(NSInteger sta, NSString * _Nullable msg) {
[KBHUD dismiss];
[KBHUD showInfo:(sta == KB_PAY_ERROR_CODE ? @"支付失败" : @"支付成功")];
if (sta == KB_PAY_SUCC_CODE) {
[KBHUD showInfo:(sta == ERROR_CODE ? @"支付失败" : @"支付成功")];
if (sta == SUCCESS_CODE) {
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
if (handler) handler(@"成功", nil);
} else {

View File

@@ -18,12 +18,12 @@
if (needShow) { [KBHUD dismiss]; }
if (error) {
if (completion) completion(KB_PAY_ERROR_CODE, error.localizedDescription ?: @"网络错误");
if (completion) completion(ERROR_CODE, error.localizedDescription ?: @"网络错误");
return;
}
NSInteger sta = [self.class extractStatusFromResponseObject:jsonOrData response:response];
NSString *msg = [self.class extractMessageFromResponseObject:jsonOrData] ?: (sta == KB_PAY_SUCC_CODE ? @"OK" : @"失败");
NSString *msg = [self.class extractMessageFromResponseObject:jsonOrData] ?: (sta == SUCCESS_CODE ? @"OK" : @"失败");
if (completion) completion(sta, msg);
}];
}
@@ -36,21 +36,21 @@
NSDictionary *d = (NSDictionary *)obj;
id code = d[@"code"] ?: d[@"status"] ?: d[@"retcode"];
if ([code isKindOfClass:NSNumber.class]) {
return [((NSNumber *)code) integerValue] == 0 ? KB_PAY_SUCC_CODE : KB_PAY_ERROR_CODE;
return [((NSNumber *)code) integerValue] == 0 ? SUCCESS_CODE : ERROR_CODE;
}
if ([code isKindOfClass:NSString.class]) {
// "0"
return [((NSString *)code) integerValue] == 0 ? KB_PAY_SUCC_CODE : KB_PAY_ERROR_CODE;
return [((NSString *)code) integerValue] == 0 ? SUCCESS_CODE : ERROR_CODE;
}
id success = d[@"success"] ?: d[@"ok"];
if ([success respondsToSelector:@selector(boolValue)]) {
return [success boolValue] ? KB_PAY_SUCC_CODE : KB_PAY_ERROR_CODE;
return [success boolValue] ? SUCCESS_CODE : ERROR_CODE;
}
}
// HTTP 2xx
NSInteger http = 0;
if ([resp isKindOfClass:NSHTTPURLResponse.class]) { http = ((NSHTTPURLResponse *)resp).statusCode; }
return (http >= 200 && http < 300) ? KB_PAY_SUCC_CODE : KB_PAY_ERROR_CODE;
return (http >= 200 && http < 300) ? SUCCESS_CODE : ERROR_CODE;
}
+ (NSString *)extractMessageFromResponseObject:(id)obj {

View File

@@ -0,0 +1,77 @@
//
// WMDragView.h
// WMDragView
//
// Created by zhengwenming on 2016/12/16.
//
//
#import <UIKit/UIKit.h>
// 拖曳view的方向
typedef NS_ENUM(NSInteger, WMDragDirection) {
WMDragDirectionAny, /**< 任意方向 */
WMDragDirectionHorizontal, /**< 水平方向 */
WMDragDirectionVertical, /**< 垂直方向 */
};
@interface WMDragView : UIView
/**
是不是能拖曳默认为YES
YES能拖曳
NO不能拖曳
*/
@property (nonatomic,assign) BOOL dragEnable;
/**
活动范围默认为父视图的frame范围内因为拖出父视图后无法点击也没意义
如果设置了,则会在给定的范围内活动
如果没设置,则会在父视图范围内活动
注意设置的frame不要大于父视图范围
注意设置的frame为0000表示活动的范围为默认的父视图frame如果想要不能活动请设置dragEnable这个属性为NO
*/
@property (nonatomic,assign) CGRect freeRect;
/**
拖曳的方向默认为any任意方向
*/
@property (nonatomic,assign) WMDragDirection dragDirection;
/**
contentView内部懒加载的一个UIImageView
开发者也可以自定义控件添加到本view中
注意最好不要同时使用内部的imageView和button
*/
@property (nonatomic,strong) UIImageView *imageView;
/**
contentView内部懒加载的一个UIButton
开发者也可以自定义控件添加到本view中
注意最好不要同时使用内部的imageView和button
*/
@property (nonatomic,strong) UIButton *button;
/**
是不是总保持在父视图边界默认为NO,没有黏贴边界效果
isKeepBounds = YES它将自动黏贴边界而且是最近的边界
isKeepBounds = NO 它将不会黏贴在边界它是free(自由)状态跟随手指到任意位置但是也不可以拖出给定的范围frame
*/
@property (nonatomic,assign) BOOL isKeepBounds;
/**
点击的回调block
*/
@property (nonatomic,copy) void(^clickDragViewBlock)(WMDragView *dragView);
/**
开始拖动的回调block
*/
@property (nonatomic,copy) void(^beginDragBlock)(WMDragView *dragView);
/**
拖动中的回调block
*/
@property (nonatomic,copy) void(^duringDragBlock)(WMDragView *dragView);
/**
结束拖动的回调block
*/
@property (nonatomic,copy) void(^endDragBlock)(WMDragView *dragView);
@end

View File

@@ -0,0 +1,235 @@
//
// WMDragView.m
// WMDragView
//
// Created by zhengwenming on 2016/12/16.
//
//
#import "WMDragView.h"
@interface WMDragView ()<UIGestureRecognizerDelegate>
/**
viewcontentViewForDragcontentView
contentViewForDrag
*/
@property (nonatomic,strong) UIView *contentViewForDrag;
@property (nonatomic,assign) CGPoint startPoint;
@property (nonatomic,strong) UIPanGestureRecognizer *panGestureRecognizer;
@property (nonatomic,assign) CGFloat previousScale;
@end
@implementation WMDragView
-(UIImageView *)imageView{
if (_imageView==nil) {
_imageView = [[UIImageView alloc]init];
_imageView.userInteractionEnabled = YES;
_imageView.clipsToBounds = YES;
[self.contentViewForDrag addSubview:_imageView];
}
return _imageView;
}
-(UIButton *)button{
if (_button==nil) {
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.clipsToBounds = YES;
_button.userInteractionEnabled = NO;
[self.contentViewForDrag addSubview:_button];
}
return _button;
}
-(UIView *)contentViewForDrag{
if (_contentViewForDrag==nil) {
_contentViewForDrag = [[UIView alloc]init];
_contentViewForDrag.clipsToBounds = YES;
}
return _contentViewForDrag;
}
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self addSubview:self.contentViewForDrag];
[self setUp];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder{
self = [super initWithCoder:coder];
if (self) {
[self setUp];
}
return self;
}
-(void)layoutSubviews{
[super layoutSubviews];
if (self.freeRect.origin.x!=0||self.freeRect.origin.y!=0||self.freeRect.size.height!=0||self.freeRect.size.width!=0) {
//freeRect--
}else{
//freeRect--frame
self.freeRect = (CGRect){CGPointZero,self.superview.bounds.size};
}
_imageView.frame = (CGRect){CGPointZero,self.bounds.size};
_button.frame = (CGRect){CGPointZero,self.bounds.size};
self.contentViewForDrag.frame = (CGRect){CGPointZero,self.bounds.size};
}
-(void)setUp{
self.dragEnable = YES;//
self.clipsToBounds = YES;
self.isKeepBounds = NO;
self.backgroundColor = [UIColor lightGrayColor];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickDragView)];
[self addGestureRecognizer:singleTap];
//
self.panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragAction:)];
self.panGestureRecognizer.minimumNumberOfTouches = 1;
self.panGestureRecognizer.maximumNumberOfTouches = 1;
self.panGestureRecognizer.delegate = self;
[self addGestureRecognizer:self.panGestureRecognizer];
}
- (void)setIsKeepBounds:(BOOL)isKeepBounds{
_isKeepBounds = isKeepBounds;
if(isKeepBounds){
[self keepBounds];
}
}
-(void)setFreeRect:(CGRect)freeRect{
_freeRect = freeRect;
[self keepBounds];
}
//-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
// return self.dragEnable;
//}
/**
@param pan
*/
-(void)dragAction:(UIPanGestureRecognizer *)pan{
if(self.dragEnable==NO)return;
switch (pan.state) {
case UIGestureRecognizerStateBegan:{//
if (self.beginDragBlock) {
self.beginDragBlock(self);
}
//translation0translation
[pan setTranslation:CGPointZero inView:self];
//
self.startPoint = [pan translationInView:self];
break;
}
case UIGestureRecognizerStateChanged:{//
// = -
if (self.duringDragBlock) {
self.duringDragBlock(self);
}
CGPoint point = [pan translationInView:self];
float dx;
float dy;
switch (self.dragDirection) {
case WMDragDirectionAny:
dx = point.x - self.startPoint.x;
dy = point.y - self.startPoint.y;
break;
case WMDragDirectionHorizontal:
dx = point.x - self.startPoint.x;
dy = 0;
break;
case WMDragDirectionVertical:
dx = 0;
dy = point.y - self.startPoint.y;
break;
default:
dx = point.x - self.startPoint.x;
dy = point.y - self.startPoint.y;
break;
}
//view
CGPoint newCenter = CGPointMake(self.center.x + dx, self.center.y + dy);
//view
self.center = newCenter;
// translation0translation
[pan setTranslation:CGPointZero inView:self];
break;
}
case UIGestureRecognizerStateEnded:{//
[self keepBounds];
if (self.endDragBlock) {
self.endDragBlock(self);
}
break;
}
default:
break;
}
}
//
-(void)clickDragView{
if (self.clickDragViewBlock) {
self.clickDragViewBlock(self);
}
}
//
- (void)keepBounds{
//
float centerX = self.freeRect.origin.x+(self.freeRect.size.width - self.frame.size.width)/2;
CGRect rect = self.frame;
if (self.isKeepBounds==NO) {//
if (self.frame.origin.x < self.freeRect.origin.x) {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:@"leftMove" context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
rect.origin.x = self.freeRect.origin.x;
self.frame = rect;
[UIView commitAnimations];
} else if(self.freeRect.origin.x+self.freeRect.size.width < self.frame.origin.x+self.frame.size.width){
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:@"rightMove" context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
rect.origin.x = self.freeRect.origin.x+self.freeRect.size.width-self.frame.size.width;
self.frame = rect;
[UIView commitAnimations];
}
}else if(self.isKeepBounds==YES){//
if (self.frame.origin.x< centerX) {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:@"leftMove" context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
rect.origin.x = self.freeRect.origin.x;
self.frame = rect;
[UIView commitAnimations];
} else {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:@"rightMove" context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
rect.origin.x =self.freeRect.origin.x+self.freeRect.size.width - self.frame.size.width;
self.frame = rect;
[UIView commitAnimations];
}
}
if (self.frame.origin.y < self.freeRect.origin.y) {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:@"topMove" context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
rect.origin.y = self.freeRect.origin.y;
self.frame = rect;
[UIView commitAnimations];
} else if(self.freeRect.origin.y+self.freeRect.size.height< self.frame.origin.y+self.frame.size.height){
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:@"bottomMove" context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
rect.origin.y = self.freeRect.origin.y+self.freeRect.size.height-self.frame.size.height;
self.frame = rect;
[UIView commitAnimations];
}
}
@end