未验证 提交 7cd549fe 编写于 作者: W WangLao100 提交者: GitHub

Merge pull request #894 from didi/feature/ios-mc

自定义 手势
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "DoraemonMCMessagePackager.h" #import "DoraemonMCMessagePackager.h"
#import "DoraemonMCEventHandler.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoraemonMCCommandExcutor : NSObject @interface DoraemonMCCommandExcutor : NSObject
...@@ -17,6 +17,10 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -17,6 +17,10 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)excuteMessage:(DoraemonMCMessage *)message; + (void)excuteMessage:(DoraemonMCMessage *)message;
//增加自定义事件
+ (void)addCustomMessage:(NSString *)type eventHandlerName:(DoraemonMCEventHandler *)eventHandler;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#import "DoraemonMCCommandExcutor.h" #import "DoraemonMCCommandExcutor.h"
#import "DoraemonMCEventHandler.h" #import "DoraemonMCEventHandler.h"
static NSMutableDictionary *eventHandlerMap = nil;
static NSMutableDictionary *externalEventHandlerMap = nil;
@implementation DoraemonMCCommandExcutor @implementation DoraemonMCCommandExcutor
+ (void)excuteMessageStrFromNet:(NSString *)message { + (void)excuteMessageStrFromNet:(NSString *)message {
...@@ -17,7 +20,6 @@ ...@@ -17,7 +20,6 @@
} }
+ (void)excuteMessage:(DoraemonMCMessage *)message { + (void)excuteMessage:(DoraemonMCMessage *)message {
static NSDictionary *eventHandlerMap = nil ;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
DoraemonMCReuseCellEventHandler *handlerReuseCell = [DoraemonMCReuseCellEventHandler new]; DoraemonMCReuseCellEventHandler *handlerReuseCell = [DoraemonMCReuseCellEventHandler new];
...@@ -29,6 +31,7 @@ ...@@ -29,6 +31,7 @@
@(DoraemonMCMessageTypeTextInput) : [DoraemonMCTextFiledEventHandler new], @(DoraemonMCMessageTypeTextInput) : [DoraemonMCTextFiledEventHandler new],
@(DoraemonMCMessageTypeTarbarSelected) : [DoraemonMCTabbarEventHandler new] @(DoraemonMCMessageTypeTarbarSelected) : [DoraemonMCTabbarEventHandler new]
}; };
externalEventHandlerMap = [NSMutableDictionary new];
}); });
[eventHandlerMap enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull typeNumber, DoraemonMCEventHandler * _Nonnull eventHandler, BOOL * _Nonnull stop) { [eventHandlerMap enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull typeNumber, DoraemonMCEventHandler * _Nonnull eventHandler, BOOL * _Nonnull stop) {
...@@ -38,6 +41,34 @@ ...@@ -38,6 +41,34 @@
} }
}]; }];
[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 @end
...@@ -18,6 +18,12 @@ ...@@ -18,6 +18,12 @@
indexPath:(NSIndexPath *)indexPath indexPath:(NSIndexPath *)indexPath
messageType:(DoraemonMCMessageType)type; messageType:(DoraemonMCMessageType)type;
+ (DoraemonMCMessage *)sendCustomMessageWithView:(UIView *)view
eventInfo:(NSDictionary *)eventInfo
messageType:(NSString *)type;
@end @end
...@@ -29,5 +29,18 @@ ...@@ -29,5 +29,18 @@
} }
} }
+ (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 @end
...@@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)handleEvent:(DoraemonMCMessage*)eventInfo; - (BOOL)handleEvent:(DoraemonMCMessage*)eventInfo;
- (UIView *)fetchTargetView;
@end @end
@interface DoraemonMCGestureRecognizerEventHandler : DoraemonMCEventHandler @interface DoraemonMCGestureRecognizerEventHandler : DoraemonMCEventHandler
......
...@@ -28,7 +28,8 @@ typedef NS_ENUM(NSInteger , DoraemonMCMessageType) { ...@@ -28,7 +28,8 @@ typedef NS_ENUM(NSInteger , DoraemonMCMessageType) {
// 消息类型 // 消息类型
@property (nonatomic , assign) DoraemonMCMessageType type; @property (nonatomic , assign) DoraemonMCMessageType type;
// 自定义消息类型
@property (nonatomic , assign) NSString * customType;
// 控件的xPath // 控件的xPath
@property (nonatomic , copy ) NSString *xPath; @property (nonatomic , copy ) NSString *xPath;
...@@ -54,6 +55,13 @@ typedef NS_ENUM(NSInteger , DoraemonMCMessageType) { ...@@ -54,6 +55,13 @@ typedef NS_ENUM(NSInteger , DoraemonMCMessageType) {
indexPath:(NSIndexPath *)indexPath indexPath:(NSIndexPath *)indexPath
messageType:(DoraemonMCMessageType)type; messageType:(DoraemonMCMessageType)type;
/**
自定义事件
*/
+ (DoraemonMCMessage *)packageCustomMessageWithView:(UIView *)view
eventInfo:(NSDictionary *)eventInfo
messageType:(NSString *)type;
/*** /***
根据从网络上获取的消息字符串, 解析出消息对象 根据从网络上获取的消息字符串, 解析出消息对象
*/ */
......
...@@ -15,7 +15,7 @@ static NSString const *kVcClsNameKey = @"vcClsName"; ...@@ -15,7 +15,7 @@ static NSString const *kVcClsNameKey = @"vcClsName";
static NSString const *kEventInfoKey = @"eventInfo"; static NSString const *kEventInfoKey = @"eventInfo";
static NSString const *kXpathKey = @"xPath"; static NSString const *kXpathKey = @"xPath";
static NSString const *kTypeKey = @"type"; static NSString const *kTypeKey = @"type";
static NSString const *kcustomTypeKey =@"customType";
@implementation DoraemonMCMessagePackager @implementation DoraemonMCMessagePackager
/** /**
...@@ -100,6 +100,25 @@ static NSString const *kTypeKey = @"type"; ...@@ -100,6 +100,25 @@ static NSString const *kTypeKey = @"type";
} }
/*
* 自定义事件
*/
+ (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 @@ static NSString const *kTypeKey = @"type"; ...@@ -107,6 +126,7 @@ static NSString const *kTypeKey = @"type";
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[messageString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:NULL]; NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[messageString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:NULL];
DoraemonMCMessage *messageInstance = [[DoraemonMCMessage alloc] init]; DoraemonMCMessage *messageInstance = [[DoraemonMCMessage alloc] init];
messageInstance.type = [dict[kTypeKey] integerValue]; messageInstance.type = [dict[kTypeKey] integerValue];
messageInstance.customType = dict[kcustomTypeKey];
messageInstance.xPath = dict[kXpathKey]; messageInstance.xPath = dict[kXpathKey];
messageInstance.eventInfo = dict[kEventInfoKey]; messageInstance.eventInfo = dict[kEventInfoKey];
messageInstance.currentVCClassName = dict[kVcClsNameKey]; messageInstance.currentVCClassName = dict[kVcClsNameKey];
...@@ -119,6 +139,7 @@ static NSString const *kTypeKey = @"type"; ...@@ -119,6 +139,7 @@ static NSString const *kTypeKey = @"type";
@implementation DoraemonMCMessage @implementation DoraemonMCMessage
- (NSString *)toMessageString { - (NSString *)toMessageString {
NSDictionary *dict = @{ NSDictionary *dict = @{
kTypeKey : @(self.type), kTypeKey : @(self.type),
kXpathKey : self.xPath?:@"", kXpathKey : self.xPath?:@"",
...@@ -126,6 +147,15 @@ static NSString const *kTypeKey = @"type"; ...@@ -126,6 +147,15 @@ static NSString const *kTypeKey = @"type";
kVcClsNameKey: self.currentVCClassName?:@"", kVcClsNameKey: self.currentVCClassName?:@"",
kIsFirstResponderKey : @(self.isFirstResponder) 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]) { if ([NSJSONSerialization isValidJSONObject:dict]) {
return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:NULL] encoding:NSUTF8StringEncoding]; return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:NULL] encoding:NSUTF8StringEncoding];
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
0977CCE0269F394100A6463E /* DoraemonDemoMultiControlViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0977CCDF269F394000A6463E /* DoraemonDemoMultiControlViewController.m */; }; 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 */; }; 09B042C526A8585500045D2A /* DoraemonDemoMultiConLongPressGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 09B042C426A8585500045D2A /* DoraemonDemoMultiConLongPressGesture.m */; };
09B042C926A860B400045D2A /* DoraemonDemoMultiConPinchGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 09B042C826A860B400045D2A /* DoraemonDemoMultiConPinchGesture.m */; }; 09B042C926A860B400045D2A /* DoraemonDemoMultiConPinchGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 09B042C826A860B400045D2A /* DoraemonDemoMultiConPinchGesture.m */; };
09B042CD26A8760E00045D2A /* DoraemonDemoMultiConRotationGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 09B042CC26A8760E00045D2A /* DoraemonDemoMultiConRotationGesture.m */; }; 09B042CD26A8760E00045D2A /* DoraemonDemoMultiConRotationGesture.m in Sources */ = {isa = PBXBuildFile; fileRef = 09B042CC26A8760E00045D2A /* DoraemonDemoMultiConRotationGesture.m */; };
...@@ -57,6 +58,8 @@ ...@@ -57,6 +58,8 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
0977CCDE269F394000A6463E /* DoraemonDemoMultiControlViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiControlViewController.h; sourceTree = "<group>"; }; 0977CCDE269F394000A6463E /* DoraemonDemoMultiControlViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiControlViewController.h; sourceTree = "<group>"; };
0977CCDF269F394000A6463E /* DoraemonDemoMultiControlViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DoraemonDemoMultiControlViewController.m; sourceTree = "<group>"; }; 0977CCDF269F394000A6463E /* DoraemonDemoMultiControlViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DoraemonDemoMultiControlViewController.m; sourceTree = "<group>"; };
097F6DA126D53E5D00841403 /* DoraemonDemoMultiSlideView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiSlideView.h; sourceTree = "<group>"; };
097F6DA226D53E5D00841403 /* DoraemonDemoMultiSlideView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DoraemonDemoMultiSlideView.m; sourceTree = "<group>"; };
09B042C326A8585500045D2A /* DoraemonDemoMultiConLongPressGesture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiConLongPressGesture.h; sourceTree = "<group>"; }; 09B042C326A8585500045D2A /* DoraemonDemoMultiConLongPressGesture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiConLongPressGesture.h; sourceTree = "<group>"; };
09B042C426A8585500045D2A /* DoraemonDemoMultiConLongPressGesture.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DoraemonDemoMultiConLongPressGesture.m; sourceTree = "<group>"; }; 09B042C426A8585500045D2A /* DoraemonDemoMultiConLongPressGesture.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DoraemonDemoMultiConLongPressGesture.m; sourceTree = "<group>"; };
09B042C726A860B400045D2A /* DoraemonDemoMultiConPinchGesture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiConPinchGesture.h; sourceTree = "<group>"; }; 09B042C726A860B400045D2A /* DoraemonDemoMultiConPinchGesture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoraemonDemoMultiConPinchGesture.h; sourceTree = "<group>"; };
...@@ -172,6 +175,8 @@ ...@@ -172,6 +175,8 @@
09B042D426A877ED00045D2A /* DoraemonDemoMultiConScreenEdgePanGesture.m */, 09B042D426A877ED00045D2A /* DoraemonDemoMultiConScreenEdgePanGesture.m */,
09B042D726A8781A00045D2A /* DoraemonDemoMultiConTapGesture.h */, 09B042D726A8781A00045D2A /* DoraemonDemoMultiConTapGesture.h */,
09B042D826A8781A00045D2A /* DoraemonDemoMultiConTapGesture.m */, 09B042D826A8781A00045D2A /* DoraemonDemoMultiConTapGesture.m */,
097F6DA126D53E5D00841403 /* DoraemonDemoMultiSlideView.h */,
097F6DA226D53E5D00841403 /* DoraemonDemoMultiSlideView.m */,
); );
path = MultiControl; path = MultiControl;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -597,6 +602,7 @@ ...@@ -597,6 +602,7 @@
DAE7BFAD20205C20008D49D8 /* NSObject+Runtime.m in Sources */, DAE7BFAD20205C20008D49D8 /* NSObject+Runtime.m in Sources */,
DABBE3B521D3AA4D0070518E /* DoraemonWKWebViewViewController.m in Sources */, DABBE3B521D3AA4D0070518E /* DoraemonWKWebViewViewController.m in Sources */,
0977CCE0269F394100A6463E /* DoraemonDemoMultiControlViewController.m in Sources */, 0977CCE0269F394100A6463E /* DoraemonDemoMultiControlViewController.m in Sources */,
097F6DA326D53E5D00841403 /* DoraemonDemoMultiSlideView.m in Sources */,
DAFE052D21BD4A4D00F97A59 /* DoraemonDemoMockGPSAnnotation.m in Sources */, DAFE052D21BD4A4D00F97A59 /* DoraemonDemoMockGPSAnnotation.m in Sources */,
DAFE052921BD4A4D00F97A59 /* DoraemonDemoCrashViewController.m in Sources */, DAFE052921BD4A4D00F97A59 /* DoraemonDemoCrashViewController.m in Sources */,
DA0C6F3A1FDEBE3800F43588 /* TestPlugin.m in Sources */, DA0C6F3A1FDEBE3800F43588 /* TestPlugin.m in Sources */,
...@@ -771,14 +777,14 @@ ...@@ -771,14 +777,14 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
DEBUG_INFORMATION_FORMAT = dwarf; DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 46A29A7ADN; DEVELOPMENT_TEAM = 7M2BQXS6D5;
ENABLE_BITCODE = YES; ENABLE_BITCODE = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DoraemonKitDemo/DoraemonKitDemo-PrefixHeader.pch"; GCC_PREFIX_HEADER = "DoraemonKitDemo/DoraemonKitDemo-PrefixHeader.pch";
INFOPLIST_FILE = DoraemonKitDemo/Info.plist; INFOPLIST_FILE = DoraemonKitDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0; IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 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)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
......
...@@ -16,6 +16,56 @@ ...@@ -16,6 +16,56 @@
#import "DoraemonDemoMultiConSwipeGesture.h" #import "DoraemonDemoMultiConSwipeGesture.h"
#import "DoraemonDemoMultiConTapGesture.h" #import "DoraemonDemoMultiConTapGesture.h"
#import "DoraemonDemoMultiConScreenEdgePanGesture.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 () @interface DoraemonDemoMultiControlViewController ()
@property (nonatomic,strong) UIScrollView * superScrollView; @property (nonatomic,strong) UIScrollView * superScrollView;
@end @end
...@@ -27,7 +77,7 @@ ...@@ -27,7 +77,7 @@
self.title = DoraemonDemoLocalizedString(@"一机多控Demo"); self.title = DoraemonDemoLocalizedString(@"一机多控Demo");
self.superScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds]; 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]; [self.view addSubview:self.superScrollView];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.doraemon_width, 60)]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.doraemon_width, 60)];
...@@ -52,20 +102,27 @@ ...@@ -52,20 +102,27 @@
[btn_3 addTarget:self action:@selector(controlEvent3) forControlEvents:UIControlEventTouchUpInside]; [btn_3 addTarget:self action:@selector(controlEvent3) forControlEvents:UIControlEventTouchUpInside];
[self.superScrollView addSubview:btn_3]; [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.placeholder = @"输入文案测试";
field_1.clearButtonMode = UITextFieldViewModeAlways; field_1.clearButtonMode = UITextFieldViewModeAlways;
field_1.backgroundColor = [UIColor whiteColor]; field_1.backgroundColor = [UIColor whiteColor];
[self.superScrollView addSubview:field_1]; [self.superScrollView addSubview:field_1];
//输入 UITextView 文本 //输入 UITextView 文本
UITextView *textView_1 = [[UITextView alloc]initWithFrame:CGRectMake(60, field_1.doraemon_bottom+20, self.view.doraemon_width-120, 60)]; 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; textView_1.layer.borderWidth = 0.5;
...@@ -73,23 +130,15 @@ ...@@ -73,23 +130,15 @@
textView_1.backgroundColor = [UIColor whiteColor]; textView_1.backgroundColor = [UIColor whiteColor];
[self.superScrollView addSubview:textView_1]; [self.superScrollView addSubview:textView_1];
//输入 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];
// 单击 UITapGestureRecognizer textView_2.backgroundColor = [UIColor whiteColor];
[self.superScrollView addSubview:textView_2];
//左右滑动 UISwipeGestureRecognizer
//旋转 UISwipeGestureRecognizer
//长按 //长按
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.backgroundColor = [UIColor orangeColor];
[longPress setTitle:DoraemonDemoLocalizedString(@"长安点击事件") forState:UIControlStateNormal]; [longPress setTitle:DoraemonDemoLocalizedString(@"长安点击事件") forState:UIControlStateNormal];
[longPress addTarget:self action:@selector(longPressEvent) forControlEvents:UIControlEventTouchUpInside]; [longPress addTarget:self action:@selector(longPressEvent) forControlEvents:UIControlEventTouchUpInside];
...@@ -132,13 +181,10 @@ ...@@ -132,13 +181,10 @@
[screenEdgePan addTarget:self action:@selector(screenEdgePanEvent) forControlEvents:UIControlEventTouchUpInside]; [screenEdgePan addTarget:self action:@selector(screenEdgePanEvent) forControlEvents:UIControlEventTouchUpInside];
[self.superScrollView addSubview:screenEdgePan]; [self.superScrollView addSubview:screenEdgePan];
// 无法识别的手势, 通过touchesBegan 方法来识别
} }
- (void)controlEvent{ - (void)controlEvent{
...@@ -207,3 +253,5 @@ ...@@ -207,3 +253,5 @@
[self.navigationController pushViewController:screenEdgePan animated:YES]; [self.navigationController pushViewController:screenEdgePan animated:YES];
} }
@end @end
//
// DoraemonDemoMultiSlideView.h
// DoraemonKitDemo
//
// Created by wzp on 2021/8/24.
// Copyright © 2021 yixiang. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface DoraemonDemoMultiSlideView : UIView
@end
NS_ASSUME_NONNULL_END
//
// DoraemonDemoMultiSlideView.m
// DoraemonKitDemo
//
// Created by wzp on 2021/8/24.
// Copyright © 2021 yixiang. All rights reserved.
//
#import "DoraemonDemoMultiSlideView.h"
#import <Masonry/Masonry.h>
#import "DoraemonMCCommandGenerator.h"
typedef void(^CommonActionBlock)(id);
@interface DoraemonDemoMultiSlideView ()<UIGestureRecognizerDelegate>
@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
...@@ -17,4 +17,5 @@ target 'DoraemonKitDemo' do ...@@ -17,4 +17,5 @@ target 'DoraemonKitDemo' do
pod 'FBRetainCycleDetector', :git => 'git@github.com:facebook/FBRetainCycleDetector.git', :branch => 'master' pod 'FBRetainCycleDetector', :git => 'git@github.com:facebook/FBRetainCycleDetector.git', :branch => 'master'
# pod 'fishhook', '~> 0.2' # pod 'fishhook', '~> 0.2'
pod 'YYDebugDatabase', '~> 2.1' pod 'YYDebugDatabase', '~> 2.1'
pod 'Masonry', '0.6.3'
end end
...@@ -69,6 +69,7 @@ PODS: ...@@ -69,6 +69,7 @@ PODS:
- libwebp/mux (1.1.0): - libwebp/mux (1.1.0):
- libwebp/demux - libwebp/demux
- libwebp/webp (1.1.0) - libwebp/webp (1.1.0)
- Masonry (0.6.3)
- SDWebImage (5.11.1): - SDWebImage (5.11.1):
- SDWebImage/Core (= 5.11.1) - SDWebImage/Core (= 5.11.1)
- SDWebImage/Core (5.11.1) - SDWebImage/Core (5.11.1)
...@@ -95,6 +96,7 @@ DEPENDENCIES: ...@@ -95,6 +96,7 @@ DEPENDENCIES:
- DoraemonKit/WithMultiControl (from `../../`) - DoraemonKit/WithMultiControl (from `../../`)
- DoraemonKit/WithWeex (from `../../`) - DoraemonKit/WithWeex (from `../../`)
- "FBRetainCycleDetector (from `git@github.com:facebook/FBRetainCycleDetector.git`, branch `master`)" - "FBRetainCycleDetector (from `git@github.com:facebook/FBRetainCycleDetector.git`, branch `master`)"
- Masonry (= 0.6.3)
- SDWebImage (~> 5.11) - SDWebImage (~> 5.11)
- SDWebImageWebPCoder (~> 0.8) - SDWebImageWebPCoder (~> 0.8)
- SocketRocket (~> 0.5) - SocketRocket (~> 0.5)
...@@ -109,6 +111,7 @@ SPEC REPOS: ...@@ -109,6 +111,7 @@ SPEC REPOS:
- FMDB - FMDB
- GCDWebServer - GCDWebServer
- libwebp - libwebp
- Masonry
- SDWebImage - SDWebImage
- SDWebImageWebPCoder - SDWebImageWebPCoder
- SocketRocket - SocketRocket
...@@ -138,6 +141,7 @@ SPEC CHECKSUMS: ...@@ -138,6 +141,7 @@ SPEC CHECKSUMS:
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
GCDWebServer: 2c156a56c8226e2d5c0c3f208a3621ccffbe3ce4 GCDWebServer: 2c156a56c8226e2d5c0c3f208a3621ccffbe3ce4
libwebp: 946cb3063cea9236285f7e9a8505d806d30e07f3 libwebp: 946cb3063cea9236285f7e9a8505d806d30e07f3
Masonry: ff105a956abcd19a618b2028b121cb638d7a8e2f
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
SDWebImageWebPCoder: f56ab499e3ea57dfeb6c3187dce183b10e160db0 SDWebImageWebPCoder: f56ab499e3ea57dfeb6c3187dce183b10e160db0
SocketRocket: d57c7159b83c3c6655745cd15302aa24b6bae531 SocketRocket: d57c7159b83c3c6655745cd15302aa24b6bae531
...@@ -145,6 +149,6 @@ SPEC CHECKSUMS: ...@@ -145,6 +149,6 @@ SPEC CHECKSUMS:
WXDevtool: 95b70c73c06fc3299d65bd53ba4b3e0b0087f3cb WXDevtool: 95b70c73c06fc3299d65bd53ba4b3e0b0087f3cb
YYDebugDatabase: e684a7f79fca2e3673a23347cefb822f911f3124 YYDebugDatabase: e684a7f79fca2e3673a23347cefb822f911f3124
PODFILE CHECKSUM: 77940354fa7f70dcc3caa7084c50a8b8efe8e6ce PODFILE CHECKSUM: 932a68754b6bfe4325178d4c6d3639dcd2278eb5
COCOAPODS: 1.10.1 COCOAPODS: 1.10.1
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册