From 6a1edffca86f2e5505b575eb26714986a3a2008f Mon Sep 17 00:00:00 2001 From: wangzhipng Date: Wed, 25 Aug 2021 17:20:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=20=E6=89=8B?= =?UTF-8?q?=E5=8A=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 自定义 手势 --- .../Dispatcher/DoraemonMCCommandExcutor.h | 6 +- .../Dispatcher/DoraemonMCCommandExcutor.m | 33 ++++- .../Dispatcher/DoraemonMCCommandGenerator.h | 6 + .../Dispatcher/DoraemonMCCommandGenerator.m | 13 ++ .../Event/Excutor/DoraemonMCEventHandler.h | 2 + .../DoraemonMCMessagePackager.h | 10 +- .../DoraemonMCMessagePackager.m | 32 +++- .../DoraemonKitDemo.xcodeproj/project.pbxproj | 10 +- .../DoraemonDemoMultiControlViewController.m | 96 +++++++++--- .../MultiControl/DoraemonDemoMultiSlideView.h | 17 +++ .../MultiControl/DoraemonDemoMultiSlideView.m | 138 ++++++++++++++++++ iOS/DoraemonKitDemo/Podfile | 1 + iOS/DoraemonKitDemo/Podfile.lock | 6 +- 13 files changed, 339 insertions(+), 31 deletions(-) create mode 100644 iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiSlideView.h create mode 100644 iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiSlideView.m diff --git a/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandExcutor.h b/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandExcutor.h index 74e791b13..84bb64a25 100644 --- a/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandExcutor.h +++ b/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandExcutor.h @@ -7,7 +7,7 @@ #import #import "DoraemonMCMessagePackager.h" - +#import "DoraemonMCEventHandler.h" NS_ASSUME_NONNULL_BEGIN @interface DoraemonMCCommandExcutor : NSObject @@ -17,6 +17,10 @@ NS_ASSUME_NONNULL_BEGIN + (void)excuteMessage:(DoraemonMCMessage *)message; + +//增加自定义事件 ++ (void)addCustomMessage:(NSString *)type eventHandlerName:(DoraemonMCEventHandler *)eventHandler; + @end NS_ASSUME_NONNULL_END diff --git a/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandExcutor.m b/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandExcutor.m index b2ef452ff..1361db76d 100644 --- a/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandExcutor.m +++ b/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandExcutor.m @@ -8,6 +8,9 @@ #import "DoraemonMCCommandExcutor.h" #import "DoraemonMCEventHandler.h" +static NSMutableDictionary *eventHandlerMap = nil; +static NSMutableDictionary *externalEventHandlerMap = nil; + @implementation DoraemonMCCommandExcutor + (void)excuteMessageStrFromNet:(NSString *)message { @@ -17,7 +20,6 @@ + (void)excuteMessageStrFromNet:(NSString *)message { } + (void)excuteMessage:(DoraemonMCMessage *)message { - static NSDictionary *eventHandlerMap = nil ; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ DoraemonMCReuseCellEventHandler *handlerReuseCell = [DoraemonMCReuseCellEventHandler new]; @@ -29,6 +31,7 @@ + (void)excuteMessage:(DoraemonMCMessage *)message { @(DoraemonMCMessageTypeTextInput) : [DoraemonMCTextFiledEventHandler new], @(DoraemonMCMessageTypeTarbarSelected) : [DoraemonMCTabbarEventHandler new] }; + externalEventHandlerMap = [NSMutableDictionary new]; }); [eventHandlerMap enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull typeNumber, DoraemonMCEventHandler * _Nonnull eventHandler, BOOL * _Nonnull stop) { @@ -38,6 +41,34 @@ + (void)excuteMessage:(DoraemonMCMessage *)message { } }]; + + [externalEventHandlerMap enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull typeString, DoraemonMCEventHandler * _Nonnull eventHandler, BOOL * _Nonnull stop) { + if ([message.customType isEqualToString:typeString]) { + [eventHandler handleEvent:message]; + *stop = YES; + } + }]; + + +} + +//增加自定义事件 ++ (void)addCustomMessage:(NSString *)type eventHandlerName:(DoraemonMCEventHandler *)eventHandler { + if (eventHandler && type) { + + [externalEventHandlerMap enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull typeString, DoraemonMCEventHandler * _Nonnull eventHandler, BOOL * _Nonnull stop) { + if ([type isEqualToString:typeString]) { + *stop = YES; + NSAssert(stop, @"重复添加事件"); + } + }]; + + [externalEventHandlerMap setValue:eventHandler forKey:type]; + } } + + + + @end diff --git a/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandGenerator.h b/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandGenerator.h index 7719f98b2..1eb4f309b 100644 --- a/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandGenerator.h +++ b/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandGenerator.h @@ -18,6 +18,12 @@ indexPath:(NSIndexPath *)indexPath messageType:(DoraemonMCMessageType)type; ++ (DoraemonMCMessage *)sendCustomMessageWithView:(UIView *)view + eventInfo:(NSDictionary *)eventInfo + messageType:(NSString *)type; + + + @end diff --git a/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandGenerator.m b/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandGenerator.m index b07d742e3..887074959 100644 --- a/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandGenerator.m +++ b/iOS/DoraemonKit/Src/MultiControl/Function/Dispatcher/DoraemonMCCommandGenerator.m @@ -29,5 +29,18 @@ + (void)sendMessageWithView:(UIView *)view } } + + ++ (DoraemonMCMessage *)sendCustomMessageWithView:(UIView *)view + eventInfo:(NSDictionary *)eventInfo + messageType:(NSString *)type { + + DoraemonMCMessage *message = [DoraemonMCMessagePackager packageCustomMessageWithView:view + eventInfo:eventInfo + messageType:type]; + + [DoraemonMCServer sendMessage:message.toMessageString]; + return message; +} @end diff --git a/iOS/DoraemonKit/Src/MultiControl/Function/Event/Excutor/DoraemonMCEventHandler.h b/iOS/DoraemonKit/Src/MultiControl/Function/Event/Excutor/DoraemonMCEventHandler.h index f2479014e..f2cdafa09 100644 --- a/iOS/DoraemonKit/Src/MultiControl/Function/Event/Excutor/DoraemonMCEventHandler.h +++ b/iOS/DoraemonKit/Src/MultiControl/Function/Event/Excutor/DoraemonMCEventHandler.h @@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)handleEvent:(DoraemonMCMessage*)eventInfo; +- (UIView *)fetchTargetView; + @end @interface DoraemonMCGestureRecognizerEventHandler : DoraemonMCEventHandler diff --git a/iOS/DoraemonKit/Src/MultiControl/Function/MessagePackager/DoraemonMCMessagePackager.h b/iOS/DoraemonKit/Src/MultiControl/Function/MessagePackager/DoraemonMCMessagePackager.h index eb14b6ad5..5336aef1e 100644 --- a/iOS/DoraemonKit/Src/MultiControl/Function/MessagePackager/DoraemonMCMessagePackager.h +++ b/iOS/DoraemonKit/Src/MultiControl/Function/MessagePackager/DoraemonMCMessagePackager.h @@ -28,7 +28,8 @@ typedef NS_ENUM(NSInteger , DoraemonMCMessageType) { // 消息类型 @property (nonatomic , assign) DoraemonMCMessageType type; - +// 自定义消息类型 +@property (nonatomic , assign) NSString * customType; // 控件的xPath @property (nonatomic , copy ) NSString *xPath; @@ -54,6 +55,13 @@ typedef NS_ENUM(NSInteger , DoraemonMCMessageType) { indexPath:(NSIndexPath *)indexPath messageType:(DoraemonMCMessageType)type; +/** + 自定义事件 + */ ++ (DoraemonMCMessage *)packageCustomMessageWithView:(UIView *)view + eventInfo:(NSDictionary *)eventInfo + messageType:(NSString *)type; + /*** 根据从网络上获取的消息字符串, 解析出消息对象 */ diff --git a/iOS/DoraemonKit/Src/MultiControl/Function/MessagePackager/DoraemonMCMessagePackager.m b/iOS/DoraemonKit/Src/MultiControl/Function/MessagePackager/DoraemonMCMessagePackager.m index 82995de96..20a0635fe 100644 --- a/iOS/DoraemonKit/Src/MultiControl/Function/MessagePackager/DoraemonMCMessagePackager.m +++ b/iOS/DoraemonKit/Src/MultiControl/Function/MessagePackager/DoraemonMCMessagePackager.m @@ -15,7 +15,7 @@ static NSString const *kEventInfoKey = @"eventInfo"; static NSString const *kXpathKey = @"xPath"; static NSString const *kTypeKey = @"type"; - +static NSString const *kcustomTypeKey =@"customType"; @implementation DoraemonMCMessagePackager /** @@ -100,6 +100,25 @@ + (DoraemonMCMessage *)packageMessageWithView:(UIView *)view } +/* + * 自定义事件 + */ ++ (DoraemonMCMessage *)packageCustomMessageWithView:(UIView *)view + eventInfo:(NSDictionary *)eventInfo + messageType:(NSString *)type { + DoraemonMCMessage *messageInstance = [[DoraemonMCMessage alloc] init]; + messageInstance.customType = type; + messageInstance.xPath = [DoraemonMCXPathSerializer xPathStringWithView:view]; + messageInstance.eventInfo = eventInfo; + messageInstance.isFirstResponder = view.isFirstResponder; + UIViewController *vc = [DoraemonMCXPathSerializer ownerVCWithView:view]; + if (vc) { + messageInstance.currentVCClassName = NSStringFromClass(vc.class) ; + } + + return messageInstance; + +} /*** 根据从网络上获取的消息字符串, 解析出消息对象 */ @@ -107,6 +126,7 @@ + (DoraemonMCMessage *)parseMessageString:(NSString *)messageString { NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[messageString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:NULL]; DoraemonMCMessage *messageInstance = [[DoraemonMCMessage alloc] init]; messageInstance.type = [dict[kTypeKey] integerValue]; + messageInstance.customType = dict[kcustomTypeKey]; messageInstance.xPath = dict[kXpathKey]; messageInstance.eventInfo = dict[kEventInfoKey]; messageInstance.currentVCClassName = dict[kVcClsNameKey]; @@ -119,6 +139,7 @@ + (DoraemonMCMessage *)parseMessageString:(NSString *)messageString { @implementation DoraemonMCMessage - (NSString *)toMessageString { + NSDictionary *dict = @{ kTypeKey : @(self.type), kXpathKey : self.xPath?:@"", @@ -126,6 +147,15 @@ - (NSString *)toMessageString { kVcClsNameKey: self.currentVCClassName?:@"", kIsFirstResponderKey : @(self.isFirstResponder) }; + if (self.customType.length) { + dict = @{ + kcustomTypeKey : self.customType, + kXpathKey : self.xPath?:@"", + kEventInfoKey : self.eventInfo?:@{}, + kVcClsNameKey: self.currentVCClassName?:@"", + kIsFirstResponderKey : @(self.isFirstResponder) + }; + } if ([NSJSONSerialization isValidJSONObject:dict]) { return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:NULL] encoding:NSUTF8StringEncoding]; } diff --git a/iOS/DoraemonKitDemo/DoraemonKitDemo.xcodeproj/project.pbxproj b/iOS/DoraemonKitDemo/DoraemonKitDemo.xcodeproj/project.pbxproj index d28a4a36d..25b5d91b0 100644 --- a/iOS/DoraemonKitDemo/DoraemonKitDemo.xcodeproj/project.pbxproj +++ b/iOS/DoraemonKitDemo/DoraemonKitDemo.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 0977CCE0269F394100A6463E /* DoraemonDemoMultiControlViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0977CCDF269F394000A6463E /* DoraemonDemoMultiControlViewController.m */; }; + 097F6DA326D53E5D00841403 /* DoraemonDemoMultiSlideView.m in Sources */ = {isa = PBXBuildFile; fileRef = 097F6DA226D53E5D00841403 /* DoraemonDemoMultiSlideView.m */; }; 09B042C526A8585500045D2A /* DoraemonDemoMultiConLongPressGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 09B042C426A8585500045D2A /* DoraemonDemoMultiConLongPressGesture.m */; }; 09B042C926A860B400045D2A /* DoraemonDemoMultiConPinchGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 09B042C826A860B400045D2A /* DoraemonDemoMultiConPinchGesture.m */; }; 09B042CD26A8760E00045D2A /* DoraemonDemoMultiConRotationGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 09B042CC26A8760E00045D2A /* DoraemonDemoMultiConRotationGesture.m */; }; @@ -57,6 +58,8 @@ /* Begin PBXFileReference section */ 0977CCDE269F394000A6463E /* DoraemonDemoMultiControlViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiControlViewController.h; sourceTree = ""; }; 0977CCDF269F394000A6463E /* DoraemonDemoMultiControlViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DoraemonDemoMultiControlViewController.m; sourceTree = ""; }; + 097F6DA126D53E5D00841403 /* DoraemonDemoMultiSlideView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiSlideView.h; sourceTree = ""; }; + 097F6DA226D53E5D00841403 /* DoraemonDemoMultiSlideView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DoraemonDemoMultiSlideView.m; sourceTree = ""; }; 09B042C326A8585500045D2A /* DoraemonDemoMultiConLongPressGesture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiConLongPressGesture.h; sourceTree = ""; }; 09B042C426A8585500045D2A /* DoraemonDemoMultiConLongPressGesture.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DoraemonDemoMultiConLongPressGesture.m; sourceTree = ""; }; 09B042C726A860B400045D2A /* DoraemonDemoMultiConPinchGesture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiConPinchGesture.h; sourceTree = ""; }; @@ -172,6 +175,8 @@ 09B042D426A877ED00045D2A /* DoraemonDemoMultiConScreenEdgePanGesture.m */, 09B042D726A8781A00045D2A /* DoraemonDemoMultiConTapGesture.h */, 09B042D826A8781A00045D2A /* DoraemonDemoMultiConTapGesture.m */, + 097F6DA126D53E5D00841403 /* DoraemonDemoMultiSlideView.h */, + 097F6DA226D53E5D00841403 /* DoraemonDemoMultiSlideView.m */, ); path = MultiControl; sourceTree = ""; @@ -597,6 +602,7 @@ DAE7BFAD20205C20008D49D8 /* NSObject+Runtime.m in Sources */, DABBE3B521D3AA4D0070518E /* DoraemonWKWebViewViewController.m in Sources */, 0977CCE0269F394100A6463E /* DoraemonDemoMultiControlViewController.m in Sources */, + 097F6DA326D53E5D00841403 /* DoraemonDemoMultiSlideView.m in Sources */, DAFE052D21BD4A4D00F97A59 /* DoraemonDemoMockGPSAnnotation.m in Sources */, DAFE052921BD4A4D00F97A59 /* DoraemonDemoCrashViewController.m in Sources */, DA0C6F3A1FDEBE3800F43588 /* TestPlugin.m in Sources */, @@ -771,14 +777,14 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; DEBUG_INFORMATION_FORMAT = dwarf; - DEVELOPMENT_TEAM = 46A29A7ADN; + DEVELOPMENT_TEAM = 7M2BQXS6D5; ENABLE_BITCODE = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "DoraemonKitDemo/DoraemonKitDemo-PrefixHeader.pch"; INFOPLIST_FILE = DoraemonKitDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.didi.dokit.demo.test.a; + PRODUCT_BUNDLE_IDENTIFIER = com.didi.dokit.demo.test.a123; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiControlViewController.m b/iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiControlViewController.m index 607b3d68f..9b3587e78 100644 --- a/iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiControlViewController.m +++ b/iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiControlViewController.m @@ -16,6 +16,56 @@ #import "DoraemonDemoMultiConSwipeGesture.h" #import "DoraemonDemoMultiConTapGesture.h" #import "DoraemonDemoMultiConScreenEdgePanGesture.h" +#import "DoraemonMCCommandExcutor.h" +#import "DoraemonMCMessagePackager.h" +#import "DoraemonDemoMultiSlideView.h" +@interface DoraemonMCEventHandler1: DoraemonMCEventHandler + + + +@end + +@implementation DoraemonMCEventHandler1 + +- (BOOL)handleEvent:(DoraemonMCMessage*)eventInfo { + + self.messageInfo = eventInfo; + self.targetView = [self fetchTargetView]; + NSString *message = [NSString stringWithFormat:@"%@,%@",self.targetView, [self.messageInfo.eventInfo objectForKey:@"eventInfo"]]; + UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"自定义手势" message:message + delegate:nil cancelButtonTitle:@"好的" otherButtonTitles: nil]; + [alert show]; + + return YES; +} + +@end + + + +@interface DoraemonMCEventHandler2: DoraemonMCEventHandler + + + +@end + +@implementation DoraemonMCEventHandler2 + +- (BOOL)handleEvent:(DoraemonMCMessage*)eventInfo { + + self.messageInfo = eventInfo; + self.targetView = [self fetchTargetView]; + NSString *message = [NSString stringWithFormat:@"%@,%@",self.targetView, [self.messageInfo.eventInfo objectForKey:@"eventInfo"]]; + UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"自定义手势" message:message + delegate:nil cancelButtonTitle:@"好的" otherButtonTitles: nil]; + [alert show]; + + return YES; +} + +@end + + @interface DoraemonDemoMultiControlViewController () @property (nonatomic,strong) UIScrollView * superScrollView; @end @@ -27,7 +77,7 @@ - (void)viewDidLoad { self.title = DoraemonDemoLocalizedString(@"一机多控Demo"); self.superScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds]; - self.superScrollView.contentSize = CGSizeMake(self.view.doraemon_width, self.view.doraemon_height*1.2); + self.superScrollView.contentSize = CGSizeMake(self.view.doraemon_width, self.view.doraemon_height*1.3); [self.view addSubview:self.superScrollView]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.doraemon_width, 60)]; @@ -52,20 +102,27 @@ - (void)viewDidLoad { [btn_3 addTarget:self action:@selector(controlEvent3) forControlEvents:UIControlEventTouchUpInside]; [self.superScrollView addSubview:btn_3]; + // 自定义事件 + DoraemonMCEventHandler1 *customHandler1 = [DoraemonMCEventHandler1 new]; + [DoraemonMCCommandExcutor addCustomMessage:@"customType1" eventHandlerName:customHandler1]; + + + DoraemonMCEventHandler2 *customHandler2 = [DoraemonMCEventHandler2 new]; + [DoraemonMCCommandExcutor addCustomMessage:@"customType2" eventHandlerName:customHandler2]; + DoraemonDemoMultiSlideView *slideView = [[DoraemonDemoMultiSlideView alloc]initWithFrame:CGRectMake(30, btn_3.doraemon_bottom +20, btn_3.doraemon_width-60, 60)]; + [self.superScrollView addSubview:slideView]; + //输入文本 - UITextField *field_1 = [[UITextField alloc] initWithFrame:CGRectMake(60, btn_3.doraemon_bottom+20, self.view.doraemon_width-120, 60)]; + UITextField *field_1 = [[UITextField alloc] initWithFrame:CGRectMake(60, slideView.doraemon_bottom+20, self.view.doraemon_width-120, 60)]; field_1.placeholder = @"输入文案测试"; field_1.clearButtonMode = UITextFieldViewModeAlways; field_1.backgroundColor = [UIColor whiteColor]; [self.superScrollView addSubview:field_1]; - - - //输入 UITextView 文本 UITextView *textView_1 = [[UITextView alloc]initWithFrame:CGRectMake(60, field_1.doraemon_bottom+20, self.view.doraemon_width-120, 60)]; textView_1.layer.borderWidth = 0.5; @@ -73,23 +130,15 @@ - (void)viewDidLoad { textView_1.backgroundColor = [UIColor whiteColor]; [self.superScrollView addSubview:textView_1]; - - - - - // 单击 UITapGestureRecognizer - - - //左右滑动 UISwipeGestureRecognizer - - - //旋转 UISwipeGestureRecognizer - - - + //输入 UITextView 文本 + UITextView *textView_2 = [[UITextView alloc]initWithFrame:CGRectMake(60, textView_1.doraemon_bottom+20, self.view.doraemon_width-120, 60)]; + textView_2.layer.borderWidth = 0.5; + textView_2.layer.borderColor = [[UIColor lightGrayColor] CGColor]; + textView_2.backgroundColor = [UIColor whiteColor]; + [self.superScrollView addSubview:textView_2]; //长按 - UIButton *longPress = [[UIButton alloc] initWithFrame:CGRectMake(0, textView_1.doraemon_bottom+20, self.view.doraemon_width, 60)]; + UIButton *longPress = [[UIButton alloc] initWithFrame:CGRectMake(0, textView_2.doraemon_bottom+20, self.view.doraemon_width, 60)]; longPress.backgroundColor = [UIColor orangeColor]; [longPress setTitle:DoraemonDemoLocalizedString(@"长安点击事件") forState:UIControlStateNormal]; [longPress addTarget:self action:@selector(longPressEvent) forControlEvents:UIControlEventTouchUpInside]; @@ -132,13 +181,10 @@ - (void)viewDidLoad { [screenEdgePan addTarget:self action:@selector(screenEdgePanEvent) forControlEvents:UIControlEventTouchUpInside]; [self.superScrollView addSubview:screenEdgePan]; + - // 无法识别的手势, 通过touchesBegan 方法来识别 - - - } - (void)controlEvent{ @@ -207,3 +253,5 @@ -(void)screenEdgePanEvent { [self.navigationController pushViewController:screenEdgePan animated:YES]; } @end + + diff --git a/iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiSlideView.h b/iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiSlideView.h new file mode 100644 index 000000000..0e9a5f448 --- /dev/null +++ b/iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiSlideView.h @@ -0,0 +1,17 @@ +// +// DoraemonDemoMultiSlideView.h +// DoraemonKitDemo +// +// Created by wzp on 2021/8/24. +// Copyright © 2021 yixiang. All rights reserved. +// + +#import +#import +NS_ASSUME_NONNULL_BEGIN + +@interface DoraemonDemoMultiSlideView : UIView + +@end + +NS_ASSUME_NONNULL_END diff --git a/iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiSlideView.m b/iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiSlideView.m new file mode 100644 index 000000000..b9e39d6f8 --- /dev/null +++ b/iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/MultiControl/DoraemonDemoMultiSlideView.m @@ -0,0 +1,138 @@ +// +// DoraemonDemoMultiSlideView.m +// DoraemonKitDemo +// +// Created by wzp on 2021/8/24. +// Copyright © 2021 yixiang. All rights reserved. +// + +#import "DoraemonDemoMultiSlideView.h" +#import +#import "DoraemonMCCommandGenerator.h" +typedef void(^CommonActionBlock)(id); +@interface DoraemonDemoMultiSlideView () + +@property (nonatomic, strong) UIView *bgView; +@property (nonatomic, strong) UIView *slideView; +@property (nonatomic, strong) UIButton *slideButton; +@property (nonatomic, assign) CGFloat fMaxSlideValue; +@property (nonatomic, strong) UILabel *lbLockName; +@property (nonatomic, assign) int nUnlockScale; +@property (nonatomic, strong) CommonActionBlock unLockBlock; +@end + +@implementation DoraemonDemoMultiSlideView + +- (instancetype)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if(self){ + _nUnlockScale = 70; // 默认百分之七十 + + _bgView = [UIView new]; + [_bgView setBackgroundColor:[UIColor redColor]]; + _bgView.layer.cornerRadius = 12; + _bgView.clipsToBounds = YES; + [self addSubview:_bgView]; + [_bgView mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self); + }]; + // + _slideView = [UIView new]; + [_slideView setBackgroundColor:[UIColor grayColor]]; + _slideView.layer.cornerRadius = 12; + [_bgView addSubview:_slideView]; + [_slideView mas_makeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.bgView); + }]; + // + _slideButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [_slideButton setBackgroundColor:[UIColor orangeColor]]; + [_slideView addSubview:_slideButton]; + [_slideButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.leading.top.bottom.equalTo(self.slideView); + make.width.equalTo(@(50)); + }]; + + UIFont *font = [UIFont systemFontOfSize:24]; + _lbLockName = [UILabel new]; + [_lbLockName setBackgroundColor:[UIColor grayColor]]; + [_lbLockName setText:@"自定义事件"]; + [_lbLockName setTextColor:[UIColor whiteColor]]; + [_lbLockName setTextAlignment:NSTextAlignmentCenter]; + [_lbLockName setFont:font]; + [_slideView addSubview:_lbLockName]; + [_lbLockName mas_makeConstraints:^(MASConstraintMaker *make) { + make.leading.equalTo(self.slideView).offset(118); + make.trailing.equalTo(self.slideView).offset(-80); + make.height.equalTo(@(80)); + make.center.equalTo(self.slideView); + }]; + + UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(performPanGestureRecognizer:)]; + panGestureRecognizer.delegate = self; + [_slideButton addGestureRecognizer:panGestureRecognizer]; + } + + return self; +} + + +- (void)setNUnlockScale:(int)nUnlockScale +{ + if(nUnlockScale < 0 ){ + nUnlockScale = 0; + }else if(nUnlockScale > 100){ + nUnlockScale = 100; + } + _nUnlockScale = nUnlockScale; +} + + + +- (void)performPanGestureRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer +{ + _fMaxSlideValue = _bgView.frame.size.width - _slideButton.frame.size.width; + CGPoint translation = [panGestureRecognizer translationInView:_bgView]; + if(panGestureRecognizer.state == UIGestureRecognizerStateBegan){ + _lbLockName.hidden = YES; + }else if(panGestureRecognizer.state == UIGestureRecognizerStateChanged){ + if (translation.x == 1) { + [DoraemonMCCommandGenerator sendCustomMessageWithView:self eventInfo:@{@"eventInfo":@"customType1"} messageType:@"customType1"]; + } + if(translation.x > 0){ + _lbLockName.hidden = YES; + CGFloat offset = translation.x; + if(offset > _fMaxSlideValue){ + offset = _fMaxSlideValue; + } + [_slideView mas_remakeConstraints:^(MASConstraintMaker *make) { + make.leading.equalTo(self.bgView).offset(offset); + make.top.bottom.trailing.equalTo(self.bgView); + }]; + }else{ + + } + }else if(panGestureRecognizer.state == UIGestureRecognizerStateEnded || panGestureRecognizer.state == UIGestureRecognizerStateCancelled){ + if(panGestureRecognizer.state == UIGestureRecognizerStateEnded) { + [DoraemonMCCommandGenerator sendCustomMessageWithView:self eventInfo:@{@"eventInfo":@"customType2"} messageType:@"customType2"]; + } + if(translation.x > _fMaxSlideValue * self.nUnlockScale/100.0){ + [_slideView mas_remakeConstraints:^(MASConstraintMaker *make) { + make.top.bottom.trailing.equalTo(self.bgView); + make.leading.equalTo(self.bgView).offset(self.fMaxSlideValue); + }]; + _lbLockName.hidden = YES; + if(self.unLockBlock){ + self.unLockBlock(@(YES)); + } + }else{ + [_slideView mas_remakeConstraints:^(MASConstraintMaker *make) { + make.edges.equalTo(self.bgView); + }]; + _lbLockName.hidden = NO; + } + } +} + +@end diff --git a/iOS/DoraemonKitDemo/Podfile b/iOS/DoraemonKitDemo/Podfile index eb3fec6b5..7f8cb44af 100644 --- a/iOS/DoraemonKitDemo/Podfile +++ b/iOS/DoraemonKitDemo/Podfile @@ -17,4 +17,5 @@ target 'DoraemonKitDemo' do pod 'FBRetainCycleDetector', :git => 'git@github.com:facebook/FBRetainCycleDetector.git', :branch => 'master' # pod 'fishhook', '~> 0.2' pod 'YYDebugDatabase', '~> 2.1' + pod 'Masonry', '0.6.3' end diff --git a/iOS/DoraemonKitDemo/Podfile.lock b/iOS/DoraemonKitDemo/Podfile.lock index eb64da09e..a8bd4686e 100644 --- a/iOS/DoraemonKitDemo/Podfile.lock +++ b/iOS/DoraemonKitDemo/Podfile.lock @@ -69,6 +69,7 @@ PODS: - libwebp/mux (1.1.0): - libwebp/demux - libwebp/webp (1.1.0) + - Masonry (0.6.3) - SDWebImage (5.11.1): - SDWebImage/Core (= 5.11.1) - SDWebImage/Core (5.11.1) @@ -95,6 +96,7 @@ DEPENDENCIES: - DoraemonKit/WithMultiControl (from `../../`) - DoraemonKit/WithWeex (from `../../`) - "FBRetainCycleDetector (from `git@github.com:facebook/FBRetainCycleDetector.git`, branch `master`)" + - Masonry (= 0.6.3) - SDWebImage (~> 5.11) - SDWebImageWebPCoder (~> 0.8) - SocketRocket (~> 0.5) @@ -109,6 +111,7 @@ SPEC REPOS: - FMDB - GCDWebServer - libwebp + - Masonry - SDWebImage - SDWebImageWebPCoder - SocketRocket @@ -138,6 +141,7 @@ SPEC CHECKSUMS: FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a GCDWebServer: 2c156a56c8226e2d5c0c3f208a3621ccffbe3ce4 libwebp: 946cb3063cea9236285f7e9a8505d806d30e07f3 + Masonry: ff105a956abcd19a618b2028b121cb638d7a8e2f SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d SDWebImageWebPCoder: f56ab499e3ea57dfeb6c3187dce183b10e160db0 SocketRocket: d57c7159b83c3c6655745cd15302aa24b6bae531 @@ -145,6 +149,6 @@ SPEC CHECKSUMS: WXDevtool: 95b70c73c06fc3299d65bd53ba4b3e0b0087f3cb YYDebugDatabase: e684a7f79fca2e3673a23347cefb822f911f3124 -PODFILE CHECKSUM: 77940354fa7f70dcc3caa7084c50a8b8efe8e6ce +PODFILE CHECKSUM: 932a68754b6bfe4325178d4c6d3639dcd2278eb5 COCOAPODS: 1.10.1