From 7e2aedeac79a8b1f09f4c008eb9200b09411d0d4 Mon Sep 17 00:00:00 2001 From: weiry Date: Tue, 17 Mar 2020 17:42:16 +0800 Subject: [PATCH] =?UTF-8?q?ios=20=20=E6=9B=B4=E6=96=B0=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=BC=B9=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/ios.md | 17 ++++++ example/index.html | 26 +++++++++ package.json | 2 +- plugin.xml | 2 +- src/ios/JVerificationPlugin.m | 107 +++++++++++++++++++++++++++++++++- 5 files changed, 151 insertions(+), 3 deletions(-) diff --git a/doc/ios.md b/doc/ios.md index e3e4fbc..ca3f2a1 100644 --- a/doc/ios.md +++ b/doc/ios.md @@ -40,6 +40,8 @@ |logoHeight|float|LOGO图片高度| |logoOffsetY|float|LOGO图片偏移量| |logoHidden|BOOL|LOGO图片隐藏| +|logoConstraints|[float,float,float,float]|LOGO图片布局对象(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度)| +|logoHorizontalConstraints|[float,float,float,float]|LOGO图片 横屏布局(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度),横屏时优先级高于logoConstraints| + 登录按钮 @@ -49,6 +51,8 @@ |logBtnOffsetY|float|登录按钮Y偏移量| |logBtnTextColor|int|登录按钮文本颜色| |logBtnImgs|String,String,String|登录按钮背景图片添加到数组(顺序如下) @[激活状态的图片,失效状态的图片,高亮状态的图片]| +|logBtnConstraints|[float,float,float,float]|登录按钮布局对象(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度)| +|logBtnHorizontalConstraints|[float,float,float,float]|登录按钮 横屏布局(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度),横屏时优先级高于logBtnConstraints| + 手机号码 @@ -57,6 +61,8 @@ |numberColor|int|手机号码字体颜色| |numberSize|float|手机号码字体大小| |numFieldOffsetY|float|号码栏Y偏移量| +|numberConstraints|[float,float,float,float]|号码栏布局对象(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度)| +|numberHorizontalConstraints|[float,float,float,float]|号码栏 横屏布局(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度),横屏时优先级高于numberConstraints| + checkBox @@ -66,6 +72,8 @@ |checkedImg|String|checkBox选中时图片| |checkViewHidden|BOOL|checkBox是否隐藏,默认不隐藏| |privacyState|BOOL|隐私条款check框默认状态 默认:NO| +|checkViewConstraints|[float,float,float,float]|checkBox布局对象(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度)| +|checkViewHorizontalConstraints|[float,float,float,float]|checkBox横屏布局(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度),横屏优先级高于checkViewConstraints| + 隐私协议栏 @@ -79,6 +87,8 @@ |privacyComponents|String,String|隐私条款拼接文本数组| |privacyShowBookSymbol|BOOL|隐私条款是否显示书名号,默认不显示| |privacyLineSpacing|float|隐私条款行距,默认跟随系统| +|privacyConstraints|[float,float,float,float]|隐私条款布局对象(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度)| +|privacyHorizontalConstraints|[float,float,float,float]|隐私条款 横屏布局(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度),横屏下优先级高于privacyConstraints| + 隐私协议页面 @@ -98,6 +108,8 @@ |:-----:|:----:|:-----:| |sloganOffsetY|float|slogan偏移量Y| |sloganTextColor|int|slogan文字颜色| +|sloganConstraints|[float,float,float,float]|slogan布局对象(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度)| +|sloganHorizontalConstraints|[float,float,float,float]|slogan 横屏布局(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度),横屏下优先级高于sloganConstraints| + 弹窗 @@ -108,6 +120,11 @@ |windowBackgroundImage|String|弹框内部背景图片| |windowBackgroundAlpha|float|弹窗外侧 透明度 0~1.0| |windowCornerRadius|float|弹窗圆角数值| +|windowConstraints|[float,float,float,float]|弹窗布局对象(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度)| +|windowHorizontalConstraints|[float,float,float,float]|弹窗横屏布局(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度),横屏下优先级高于windowConstraints| +|windowCloseBtnImgs|[String,String]|弹窗close按钮图片 @[普通状态图片,高亮状态图片] +|windowCloseBtnConstraints|[float,float,float,float]|弹窗close按钮布局(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度) +|windowCloseBtnHorizontalConstraints|[float,float,float,float]|弹窗close按钮 横屏布局(窗口相对屏幕中心的x轴偏移量,窗口相对屏幕中心的y轴偏移量,窗口宽度,窗口高度),横屏下优先级高于windowCloseBtnConstraints| ![JVerification](https://docs.jiguang.cn/jverification/image/cutomeUI_description.png) diff --git a/example/index.html b/example/index.html index b6977de..a6ab167 100644 --- a/example/index.html +++ b/example/index.html @@ -56,6 +56,32 @@ appPrivacyColor:[0xff00f000,0xff000000] } + // var json={//弹框 + // navCustom:true, + // autoLayout:true, + // showWindow:true, + // windowConstraints:[0,0,300,300], + // windowBackgroundAlpha: 0.3, + // //logo + // logoImg:"AppIcon", + // logoConstraints:[0,-100,60,60], + // //number + // numberConstraints:[0,-42,200,14], + // //slogn + // sloganConstraints:[0,-20,200,14], + // //登录按钮 + // logBtnConstraints:[0,20,220,40], + // logBtnText:"Demo loginAuth", + // logBtnTextColor:0x0000FF, + // windowCornerRadius:10, + // privacyConstraints:[0,100,200,40], + // checkViewConstraints:[-108,100,10,10], + // windowCloseBtnConstraints:[-135,-135,20,20], + // loadingConstraints:[0,0,20,20], + // windowCloseBtnImgs:["AppIcon","AppIcon"], + // windowBackgroundImage:"AppIcon" + // } + json = JSON.stringify(json); // alert(json); JGJVerificationPlugin.setCustomUIWithConfig(json); diff --git a/package.json b/package.json index 1faf367..871d9b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jg-jverification-cordova-plugin", - "version": "1.2.4", + "version": "1.2.5", "description": "JVerification-cordova-plugin", "cordova": { "id": "jg-jverification-cordova-plugin", diff --git a/plugin.xml b/plugin.xml index e44073e..b5c0afa 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,6 +1,6 @@ JVerification-cordova-plugin diff --git a/src/ios/JVerificationPlugin.m b/src/ios/JVerificationPlugin.m index 7079442..9b50d66 100644 --- a/src/ios/JVerificationPlugin.m +++ b/src/ios/JVerificationPlugin.m @@ -423,20 +423,28 @@ - (void)setCustomUIWithConfig:(CDVInvokedUrlCommand*)command static NSString* logoHeight=@"logoHeight"; static NSString* logoOffsetY=@"logoOffsetY"; static NSString* logoHidden=@"logoHidden"; +static NSString* logoConstraints=@"logoConstraints"; +static NSString* logoHorizontalConstraints=@"logoHorizontalConstraints"; //登录按钮 static NSString* logBtnText=@"logBtnText"; static NSString* logBtnOffsetY=@"logBtnOffsetY"; static NSString* logBtnTextColor=@"logBtnTextColor"; static NSString* logBtnImgs=@"logBtnImgs"; +static NSString* logBtnConstraints=@"logBtnConstraints"; +static NSString* logBtnHorizontalConstraints=@"logBtnHorizontalConstraints"; //手机号码 static NSString* numberColor=@"numberColor"; static NSString* numberSize=@"numberSize"; static NSString* numFieldOffsetY=@"numFieldOffsetY"; +static NSString* numberConstraints=@"numberConstraints"; +static NSString* numberHorizontalConstraints=@"numberHorizontalConstraints"; //checkBox static NSString* uncheckedImg=@"uncheckedImg"; static NSString* checkedImg=@"checkedImg"; static NSString* checkViewHidden=@"checkViewHidden"; static NSString* privacyState=@"privacyState"; +static NSString* checkViewConstraints=@"checkViewConstraints"; +static NSString* checkViewHorizontalConstraints=@"checkViewHorizontalConstraints"; //隐私协议栏 static NSString* appPrivacyOne=@"appPrivacyOne"; static NSString* appPrivacyTwo=@"appPrivacyTwo"; @@ -446,6 +454,8 @@ - (void)setCustomUIWithConfig:(CDVInvokedUrlCommand*)command static NSString* privacyComponents=@"privacyComponents"; static NSString* privacyShowBookSymbol=@"privacyShowBookSymbol"; static NSString* privacyLineSpacing=@"privacyLineSpacing"; +static NSString* privacyConstraints=@"privacyConstraints"; +static NSString* privacyHorizontalConstraints=@"privacyHorizontalConstraints"; //隐私协议页面 static NSString* agreementNavBackgroundColor=@"agreementNavBackgroundColor"; static NSString* agreementNavText=@"agreementNavText"; @@ -454,15 +464,27 @@ - (void)setCustomUIWithConfig:(CDVInvokedUrlCommand*)command static NSString* agreementNavReturnImage=@"agreementNavReturnImage"; //slogan static NSString* sloganOffsetY=@"sloganOffsetY"; +static NSString* sloganConstraints=@"sloganConstraints"; +static NSString* sloganHorizontalConstraints=@"sloganHorizontalConstraints"; static NSString* sloganTextColor=@"sloganTextColor"; //弹窗 static NSString* showWindow=@"showWindow"; static NSString* windowBackgroundImage=@"windowBackgroundImage"; static NSString* windowBackgroundAlpha=@"windowBackgroundAlpha"; static NSString* windowCornerRadius=@"windowCornerRadius"; +static NSString* windowConstraints=@"windowConstraints"; +static NSString* windowHorizontalConstraints=@"windowHorizontalConstraints"; +static NSString* windowCloseBtnImgs=@"windowCloseBtnImgs"; +static NSString* windowCloseBtnConstraints=@"windowCloseBtnConstraints"; +static NSString* windowCloseBtnHorizontalConstraints=@"windowCloseBtnHorizontalConstraints"; + +//loading +static NSString* loadingConstraints=@"loadingConstraints"; +static NSString* loadingHorizontalConstraints=@"loadingHorizontalConstraints"; void setJVUIConfig(NSString* key ,NSDictionary *dict, JVUIConfig *jvUIConfig){ + //授权页面设置 if ([key containsString:authPageBackgroundImage]) { jvUIConfig.authPageBackgroundImage = [UIImage imageNamed:dict[key]]; @@ -507,6 +529,12 @@ void setJVUIConfig(NSString* key ,NSDictionary *dict, jvUIConfig.logoOffsetY =[dict[key] floatValue];//CGFloat; }else if([key containsString:logoHidden]){ jvUIConfig.logoHidden =[dict[key] boolValue];//BOOL + }else if([key containsString:logoConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.logoConstraints = configConstraintWithAttributes(consWindow); + }else if([key containsString:logoHorizontalConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.logoHorizontalConstraints = configConstraintWithAttributes(consWindow); } // 登录按钮 @@ -524,6 +552,12 @@ void setJVUIConfig(NSString* key ,NSDictionary *dict, [UIImage imageNamed:imgPaths[2]], nil]; jvUIConfig.logBtnImgs = logBtnImgs; + }else if([key containsString:logBtnConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.logBtnConstraints = configConstraintWithAttributes(consWindow); + }else if([key containsString:logBtnHorizontalConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.logBtnHorizontalConstraints = configConstraintWithAttributes(consWindow); } // 手机号码 else if([key containsString:numberColor]){ @@ -532,6 +566,12 @@ void setJVUIConfig(NSString* key ,NSDictionary *dict, jvUIConfig.numberSize = [dict[key] floatValue]; }else if([key containsString:numFieldOffsetY]){ jvUIConfig.numFieldOffsetY = [dict[key] floatValue]; + }else if([key containsString:numberConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.numberConstraints = configConstraintWithAttributes(consWindow); + }else if([key containsString:numberHorizontalConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.numberHorizontalConstraints = configConstraintWithAttributes(consWindow); } // checkBox else if([key containsString:uncheckedImg]){ @@ -542,6 +582,12 @@ void setJVUIConfig(NSString* key ,NSDictionary *dict, jvUIConfig.checkViewHidden = [dict[key] boolValue]; }else if([key containsString:privacyState]){ jvUIConfig.privacyState = [dict[key] boolValue]; + }else if([key containsString:checkViewConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.checkViewConstraints = configConstraintWithAttributes(consWindow); + }else if([key containsString:checkViewHorizontalConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.checkViewHorizontalConstraints = configConstraintWithAttributes(consWindow); } // 隐私协议栏 @@ -566,6 +612,12 @@ void setJVUIConfig(NSString* key ,NSDictionary *dict, jvUIConfig.privacyShowBookSymbol = [dict[key] boolValue]; }else if([key containsString:privacyLineSpacing]){ jvUIConfig.privacyLineSpacing = [dict[key] floatValue]; + }else if([key containsString:privacyConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.privacyConstraints = configConstraintWithAttributes(consWindow); + }else if([key containsString:privacyHorizontalConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.privacyHorizontalConstraints = configConstraintWithAttributes(consWindow); } // 隐私协议页面 @@ -586,11 +638,17 @@ void setJVUIConfig(NSString* key ,NSDictionary *dict, // slogan else if([key containsString:sloganOffsetY]){ jvUIConfig.sloganOffsetY = [dict[key] floatValue]; + }else if([key containsString:sloganConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.sloganConstraints = configConstraintWithAttributes(consWindow); + }else if([key containsString:sloganHorizontalConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.sloganHorizontalConstraints = configConstraintWithAttributes(consWindow); }else if([key containsString:sloganTextColor]){ jvUIConfig.sloganTextColor = UIColorFromRGBValue([dict[key] intValue]); } // 弹窗 - else if([key containsString:sloganOffsetY]){ + else if([key containsString:showWindow]){ jvUIConfig.showWindow = [dict[key] boolValue]; }else if([key containsString:windowBackgroundImage]){ jvUIConfig.windowBackgroundImage = [UIImage imageNamed:dict[key]]; @@ -598,6 +656,36 @@ void setJVUIConfig(NSString* key ,NSDictionary *dict, jvUIConfig.windowBackgroundAlpha = [dict[key] floatValue]; }else if([key containsString:windowCornerRadius]){ jvUIConfig.windowCornerRadius = [dict[key] floatValue]; + }else if([key containsString:windowConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.windowConstraints = configConstraintWithAttributes(consWindow); + }else if([key containsString:windowHorizontalConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.windowHorizontalConstraints = configConstraintWithAttributes(consWindow); + }else if([key containsString:windowCloseBtnImgs]){ + NSArray* imageNames = dict[key]; + NSMutableArray *images = [NSMutableArray arrayWithCapacity:3]; + for (int i = 0; i< imageNames.count; i++) { + UIImage *closeImage = [UIImage imageNamed:imageNames[i]]; + if (closeImage) { + [images addObject:closeImage]; + } + } + jvUIConfig.windowCloseBtnImgs = images; + }else if([key containsString:windowCloseBtnConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.windowCloseBtnConstraints = configConstraintWithAttributes(consWindow); + }else if([key containsString:windowCloseBtnHorizontalConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.windowCloseBtnHorizontalConstraints = configConstraintWithAttributes(consWindow); + } + //loading + else if([key containsString:loadingConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.loadingConstraints = configConstraintWithAttributes(consWindow); + }else if([key containsString:loadingHorizontalConstraints]){ + NSArray* consWindow = dict[key]; + jvUIConfig.loadingHorizontalConstraints = configConstraintWithAttributes(consWindow); } } @@ -643,4 +731,21 @@ id APNativeJSONObject(NSData *data) { return retId; } + + +NSArray *configConstraintWithAttributes(NSArray* keys){ + NSMutableArray *constraints = [NSMutableArray arrayWithCapacity:4]; + NSArray* cons = keys; + CGFloat centerX = [cons[0] floatValue]; + CGFloat centerY = [cons[1] floatValue]; + CGFloat w = [cons[2] floatValue]; + CGFloat h = [cons[3] floatValue]; + JVLayoutConstraint *constraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:centerX]; + JVLayoutConstraint *constraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterY multiplier:1 constant:centerY]; + JVLayoutConstraint *constraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:w]; + JVLayoutConstraint *constraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:h]; + [constraints addObjectsFromArray:@[constraintX,constraintY,constraintW,constraintH]]; + return constraints; +} + @end