未验证 提交 9d222d9e 编写于 作者: L litianhao3615 提交者: GitHub

Merge pull request #867 from litianhao3615/feature/ios-mc

Modify:[iOS]-一机多控,window查找添加keywindow补偿机制,优化系统手势扩展变量命名
......@@ -43,6 +43,11 @@
+ (void)do_mc_swizzleInstanceMethodWithOriginSel:(SEL)oriSel swizzledSel:(SEL)swiSel cls:(Class)cls;
/// 获取key对应的关联对象的值 自动解包成CGPoint
- (CGPoint)do_mc_point_value_forkey:(const void * _Nonnull)key ;
/// 获取key对应的关联对象的值 自动解包成CGRect
- (CGRect)do_mc_rect_value_forkey:(const void * _Nonnull)key ;
@end
@interface UIGestureRecognizer (DoraemonMCSupport)
......@@ -53,14 +58,9 @@
- (void)do_mc_handleGestureSend:(id)sender;
@property (nonatomic , assign) CGPoint do_mc_temp_p;
@property (nonatomic , assign) CGPoint do_mc_temp_location;
@property (nonatomic , assign) CGPoint do_mc_host_temp_p;
/// 主机上 手势的触摸坐标
@property (nonatomic , assign) CGPoint do_mc_location_at_host;
@property (nonatomic , assign) CGPoint do_mc_temp_Vol;
@end
......@@ -70,6 +70,15 @@
@interface UIPanGestureRecognizer (DoraemonMCSupport)
/// 主机上 平移手势的偏移距离
@property (nonatomic , assign) CGPoint do_mc_translation_at_host;
/// 主机上平移手势的加速度
@property (nonatomic , assign) CGPoint do_mc_vol_at_host;
@end
@interface UILongPressGestureRecognizer (DoraemonMCSupport)
@end
@interface UIControl (DoraemonMCSupport)
......
......@@ -60,18 +60,37 @@
});
}
- (void)setDo_mc_vol_at_host:(CGPoint)do_mc_vol_at_host
{
objc_setAssociatedObject(self, @selector(do_mc_vol_at_host), [NSValue valueWithCGPoint:do_mc_vol_at_host], OBJC_ASSOCIATION_RETAIN);
}
- (CGPoint)do_mc_vol_at_host {
return [self do_mc_point_value_forkey:_cmd];
}
- (void)setDo_mc_translation_at_host:(CGPoint)do_mc_translation_at_host {
objc_setAssociatedObject(self, @selector(do_mc_translation_at_host), [NSValue valueWithCGPoint:do_mc_translation_at_host], OBJC_ASSOCIATION_RETAIN);
}
- (CGPoint)do_mc_translation_at_host {
return [self do_mc_point_value_forkey:_cmd];
}
- (CGPoint)do_mc_translationInView:(UIView *)view {
if (CGPointEqualToPoint(CGPointZero, self.do_mc_temp_p)) {
if (CGPointEqualToPoint(CGPointZero, self.do_mc_location_at_host)) {
return [self do_mc_translationInView:view];
}
return self.do_mc_temp_p;
return self.do_mc_location_at_host;
}
- (CGPoint)do_mc_velocityInView:(UIView *)view{
if (CGPointEqualToPoint(CGPointZero, self.do_mc_temp_Vol)) {
if (CGPointEqualToPoint(CGPointZero, self.do_mc_vol_at_host)) {
return [self do_mc_translationInView:view];
}
return self.do_mc_temp_Vol;
return self.do_mc_vol_at_host;
}
......@@ -107,9 +126,6 @@
@end
@interface UILongPressGestureRecognizer (DoraemonMCSupport)
@end
@implementation UILongPressGestureRecognizer (DoraemonMCSupport)
......@@ -123,10 +139,10 @@
}
- (CGPoint)do_mc_locationInView:(UIView *)view{
if (CGPointEqualToPoint(CGPointZero, self.do_mc_temp_location)) {
if (CGPointEqualToPoint(CGPointZero, self.do_mc_location_at_host)) {
return [self do_mc_locationInView:view];
}
return self.do_mc_temp_location;
return self.do_mc_location_at_host;
}
......@@ -162,18 +178,15 @@
if (!existed) {
[self.do_mc_targetActionPairs addObject:[[DoraemonMCGestureTargetActionPair alloc] initWithTarget:target action:action sender:self]];
}
// if ([NSStringFromClass([target class]) isEqualToString:@"UIInterfaceActionSelectionTrackingController"]) {
// NSLog(@"UIInterfaceActionSelectionTrackingController");
// }else
[self do_mc_addTarget:target action:action];
// }
[self do_mc_addTarget:target action:action];
}
- (CGPoint)do_mc_locationInView:(UIView *)view{
if (CGPointEqualToPoint(CGPointZero, self.do_mc_temp_location)) {
if (CGPointEqualToPoint(CGPointZero, self.do_mc_location_at_host)) {
return [self do_mc_locationInView:view];
}
return self.do_mc_temp_location;
return self.do_mc_location_at_host;
}
- (void)do_mc_handleGestureSend:(id)sender {
......@@ -188,12 +201,6 @@
if ([DoraemonMCServer isOpen]) {
[self do_mc_handleGestureSend:sender];
}
// [self.do_mc_targetActionPairs enumerateObjectsUsingBlock:^(DoraemonMCGestureTargetActionPair * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// if ([NSStringFromClass([obj.target class]) isEqualToString:@"UIInterfaceActionSelectionTrackingController"]) {
//// NSLog(@"UIInterfaceActionSelectionTrackingController");
// [obj doAction];
// }
// }];
}
......@@ -203,7 +210,7 @@
[obj doAction];
}
}];
self.do_mc_temp_location = CGPointZero;
self.do_mc_location_at_host = CGPointZero;
}
- (void)do_mc_removeTarget:(id)target action:(SEL)action {
......@@ -233,32 +240,12 @@
}
- (void)setDo_mc_temp_p:(CGPoint)do_mc_temp_p {
objc_setAssociatedObject(self, @selector(do_mc_temp_p), [NSValue valueWithCGPoint:do_mc_temp_p], OBJC_ASSOCIATION_RETAIN);
- (void)setDo_mc_location_at_host:(CGPoint)do_mc_location_at_host {
objc_setAssociatedObject(self, @selector(do_mc_location_at_host), [NSValue valueWithCGPoint:do_mc_location_at_host], OBJC_ASSOCIATION_RETAIN);
}
- (CGPoint)do_mc_temp_p {
id value = objc_getAssociatedObject(self, _cmd);
return [value CGPointValue];
}
- (void)setDo_mc_temp_Vol:(CGPoint)temp_Vol
{
objc_setAssociatedObject(self, @selector(do_mc_temp_Vol), [NSValue valueWithCGPoint:temp_Vol], OBJC_ASSOCIATION_RETAIN);
}
- (CGPoint)do_mc_temp_Vol {
id value = objc_getAssociatedObject(self, _cmd);
return [value CGPointValue];
}
- (void)setDo_mc_temp_location:(CGPoint)do_mc_temp_location {
objc_setAssociatedObject(self, @selector(do_mc_temp_location), [NSValue valueWithCGPoint:do_mc_temp_location], OBJC_ASSOCIATION_RETAIN);
}
- (CGPoint)do_mc_temp_location {
id value = objc_getAssociatedObject(self, _cmd);
return [value CGPointValue];
- (CGPoint)do_mc_location_at_host {
return [self do_mc_point_value_forkey:_cmd];
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {}
......@@ -454,6 +441,22 @@
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{}
- (CGPoint)do_mc_point_value_forkey:(const void * _Nonnull)key {
NSValue *value = objc_getAssociatedObject(self, key);
if (![value isKindOfClass:[NSValue class]]) {
return CGPointZero;
}
return [value CGPointValue];
}
- (CGRect)do_mc_rect_value_forkey:(const void * _Nonnull)key {
NSValue *value = objc_getAssociatedObject(self, key);
if (![value isKindOfClass:[NSValue class]]) {
return CGRectZero;
}
return [value CGRectValue];;
}
@end
......@@ -88,15 +88,15 @@
CGPoint point = CGPointMake([data[@"pointX"] floatValue] , [data[@"pointY"] floatValue] );
pan.view.center = CGPointMake(point.x, point.y);
if (pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateCancelled) {
pan.do_mc_temp_p = CGPointZero;
pan.do_mc_translation_at_host = CGPointZero;
}else {
pan.do_mc_temp_p = translation;
pan.do_mc_temp_Vol = volP;
pan.do_mc_translation_at_host = translation;
pan.do_mc_vol_at_host = volP;
}
}
CGPoint locationP = CGPointMake([eventInfo[@"lp"][@"x"] doubleValue], [eventInfo[@"lp"][@"y"] doubleValue]);
gusture.do_mc_temp_location = locationP;
gusture.do_mc_location_at_host = locationP;
gusture.state = [eventInfo[@"state"] intValue];
NSDictionary *pps = eventInfo[@"pps"];
......
......@@ -7,6 +7,7 @@
#import "DoraemonMCXPathSerializer.h"
static NSUInteger const kDoraemonMCXPathUseKeyWindowIndex = 99999;
@interface DoraemonMCXPathSerializer ()
// 如果isOneCell为true , 这个字段有值 列表容器的XPath 例如 UITableView , UICollectionView
......@@ -67,7 +68,10 @@
self.vcCls = [self.class ownerVCWithView:view];
self.windowIndex = [[[UIApplication sharedApplication] windows] indexOfObject:currentWindow];
if (self.windowIndex == NSNotFound &&
[UIApplication sharedApplication].keyWindow == currentWindow) {
self.windowIndex = kDoraemonMCXPathUseKeyWindowIndex;
}
NSMutableArray<DoraemonMCXPathNode *> *currentPathNodeList = [NSMutableArray array];
UIView *currentV = view;
......@@ -223,6 +227,9 @@
if ([UIApplication sharedApplication].windows.count > self.windowIndex) {
rootWidow = [[UIApplication sharedApplication].windows objectAtIndex:self.windowIndex];
}
if (kDoraemonMCXPathUseKeyWindowIndex == self.windowIndex) {
rootWidow = [UIApplication sharedApplication].keyWindow;
}
if (rootWidow == nil) {
return nil;
......
......@@ -78,9 +78,7 @@
txt = DoraemonDemoLocalizedString(@"通用测试Demo");
}else if(row==8){
txt = DoraemonDemoLocalizedString(@"内存泄漏测试");
}else if(row==9){
txt = DoraemonDemoLocalizedString(@"test alert view");
}else if(row == 10){
}else if(row == 9){
txt = DoraemonDemoLocalizedString(@"一机多控制测试");
}
cell.textLabel.text = txt;
......@@ -109,18 +107,6 @@
}else if(row == 8){
vc = [[DoraemonDemoMemoryLeakViewController alloc] init];
}else if(row == 9){
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"alert" message:@"alert message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"confirm");
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"cancel");
}];
[alert addAction:action];
[alert addAction:cancelAction];
[self.navigationController presentViewController:alert animated:YES completion:nil];
}else if(row == 10){
vc = [[DoraemonDemoMultiControlViewController alloc] init];
}
if (vc) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册