浏览代码

@yangdingli@增加插件IPUMobileUIPlugin.getSign

yangdingli 3 年之前
父节点
当前提交
a90056457a

+ 28 - 0
IPUMobileFunc/IPUMobileFunc.xcodeproj/project.pbxproj

@ -15,6 +15,11 @@
15 15
		045994D224247BBF0002F4A3 /* IPUScreenCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = 045994D024247BBF0002F4A3 /* IPUScreenCapture.m */; };
16 16
		04C30B9B22E6ADF200BA7B68 /* IPUTipsHUDPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 04C30B9922E6ADF200BA7B68 /* IPUTipsHUDPlugin.m */; };
17 17
		04C30B9C22E6ADF200BA7B68 /* IPUTipsHUDPlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 04C30B9A22E6ADF200BA7B68 /* IPUTipsHUDPlugin.h */; settings = {ATTRIBUTES = (Public, ); }; };
18
		76EC0CDB276056A30019B2F5 /* IPUSignStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 76EC0CD62760569E0019B2F5 /* IPUSignStoryboard.storyboard */; };
19
		76EC0CDC276056A30019B2F5 /* IPUSignViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EC0CD72760569F0019B2F5 /* IPUSignViewController.m */; };
20
		76EC0CDD276056A30019B2F5 /* IPUSignView.h in Headers */ = {isa = PBXBuildFile; fileRef = 76EC0CD8276056A10019B2F5 /* IPUSignView.h */; };
21
		76EC0CDE276056A30019B2F5 /* IPUSignViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 76EC0CD9276056A20019B2F5 /* IPUSignViewController.h */; };
22
		76EC0CDF276056A30019B2F5 /* IPUSignView.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EC0CDA276056A30019B2F5 /* IPUSignView.m */; };
18 23
		76FEC2E3275F4E2100F87937 /* IPUDialogUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 76FEC2E1275F4E2000F87937 /* IPUDialogUtil.h */; };
19 24
		76FEC2E4275F4E2100F87937 /* IPUDialogUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 76FEC2E2275F4E2100F87937 /* IPUDialogUtil.m */; };
20 25
		B2074DAB24AC82B700E6E924 /* IPUClipBoardPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = B2074DA924AC82B700E6E924 /* IPUClipBoardPlugin.m */; };
@ -153,6 +158,11 @@
153 158
		045994D024247BBF0002F4A3 /* IPUScreenCapture.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IPUScreenCapture.m; sourceTree = "<group>"; };
154 159
		04C30B9922E6ADF200BA7B68 /* IPUTipsHUDPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IPUTipsHUDPlugin.m; sourceTree = "<group>"; };
155 160
		04C30B9A22E6ADF200BA7B68 /* IPUTipsHUDPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IPUTipsHUDPlugin.h; sourceTree = "<group>"; };
161
		76EC0CD62760569E0019B2F5 /* IPUSignStoryboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = IPUSignStoryboard.storyboard; sourceTree = "<group>"; };
162
		76EC0CD72760569F0019B2F5 /* IPUSignViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IPUSignViewController.m; sourceTree = "<group>"; };
163
		76EC0CD8276056A10019B2F5 /* IPUSignView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IPUSignView.h; sourceTree = "<group>"; };
164
		76EC0CD9276056A20019B2F5 /* IPUSignViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IPUSignViewController.h; sourceTree = "<group>"; };
165
		76EC0CDA276056A30019B2F5 /* IPUSignView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IPUSignView.m; sourceTree = "<group>"; };
156 166
		76FEC2E1275F4E2000F87937 /* IPUDialogUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IPUDialogUtil.h; sourceTree = "<group>"; };
157 167
		76FEC2E2275F4E2100F87937 /* IPUDialogUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IPUDialogUtil.m; sourceTree = "<group>"; };
158 168
		B2074DA924AC82B700E6E924 /* IPUClipBoardPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IPUClipBoardPlugin.m; sourceTree = "<group>"; };
@ -288,6 +298,18 @@
288 298
/* End PBXFrameworksBuildPhase section */
289 299
290 300
/* Begin PBXGroup section */
301
		76EC0CD5276056790019B2F5 /* sign */ = {
302
			isa = PBXGroup;
303
			children = (
304
				76EC0CD62760569E0019B2F5 /* IPUSignStoryboard.storyboard */,
305
				76EC0CD8276056A10019B2F5 /* IPUSignView.h */,
306
				76EC0CDA276056A30019B2F5 /* IPUSignView.m */,
307
				76EC0CD9276056A20019B2F5 /* IPUSignViewController.h */,
308
				76EC0CD72760569F0019B2F5 /* IPUSignViewController.m */,
309
			);
310
			path = sign;
311
			sourceTree = "<group>";
312
		};
291 313
		B2445C7C21F177E8007AB82E /* Utils */ = {
292 314
			isa = PBXGroup;
293 315
			children = (
@ -431,6 +453,7 @@
431 453
		B2D71A0122A6528F00604504 /* Implementation */ = {
432 454
			isa = PBXGroup;
433 455
			children = (
456
				76EC0CD5276056790019B2F5 /* sign */,
434 457
				B2D71A0222A652E400604504 /* IPUBasicUtil.h */,
435 458
				B2D71A0322A652E400604504 /* IPUBasicUtil.m */,
436 459
				B2D71A2A22A66D2500604504 /* IPUEmailUtil.h */,
@ -513,6 +536,7 @@
513 536
				B264A22B22B33EB200714D0D /* IPUDatabaseUtil.h in Headers */,
514 537
				B28E568621F1A76E00422D15 /* IPUCustomCameraPlugin.h in Headers */,
515 538
				B28E56D621F1C3D100422D15 /* IPUAuthenticationPlugin.h in Headers */,
539
				76EC0CDE276056A30019B2F5 /* IPUSignViewController.h in Headers */,
516 540
				B2D5191D23B5ADE1008086A7 /* IPUBMapPlugin.h in Headers */,
517 541
				B2445C7F21F1780E007AB82E /* IPUDatabaseHelper.h in Headers */,
518 542
				B28E56B221F1B89E00422D15 /* IPUMailPlugin.h in Headers */,
@ -533,6 +557,7 @@
533 557
				B28E569A21F1AE0600422D15 /* IPUImageCachePlugin.h in Headers */,
534 558
				B28E567421F188DF00422D15 /* IPUUNIRestUtil.h in Headers */,
535 559
				B2DB0D61273A6BCB0010074A /* EBBannerWindow.h in Headers */,
560
				76EC0CDD276056A30019B2F5 /* IPUSignView.h in Headers */,
536 561
				B28E56D221F1C39700422D15 /* IPUSystemPermissionPlugin.h in Headers */,
537 562
				B2464E8822CF2C4E002A159E /* IPUNetworkUtil.h in Headers */,
538 563
				B22F9162274BAAA30034D77D /* IPUNFCPlugin.h in Headers */,
@ -637,6 +662,7 @@
637 662
			files = (
638 663
				B2DB0D67273A6BCB0010074A /* EBBannerView.xib in Resources */,
639 664
				B2DB0D68273A6BCB0010074A /* EBBannerViewController.xib in Resources */,
665
				76EC0CDB276056A30019B2F5 /* IPUSignStoryboard.storyboard in Resources */,
640 666
			);
641 667
			runOnlyForDeploymentPostprocessing = 0;
642 668
		};
@ -662,6 +688,7 @@
662 688
				045994D224247BBF0002F4A3 /* IPUScreenCapture.m in Sources */,
663 689
				B26A20A123CD9E0200844692 /* UIImage+IPUCompress.m in Sources */,
664 690
				04449845267997990024A808 /* IPUSysLocationPlugin.m in Sources */,
691
				76EC0CDF276056A30019B2F5 /* IPUSignView.m in Sources */,
665 692
				B281A33B22CC85B600D69B25 /* IPUAudioPlugin.m in Sources */,
666 693
				B28E568721F1A76E00422D15 /* IPUCustomCameraPlugin.m in Sources */,
667 694
				B271C33A22ADE4AC0030F3C9 /* IPUUploadDownloadUtil.m in Sources */,
@ -705,6 +732,7 @@
705 732
				B2DB0D6D273A6BCB0010074A /* EBBannerView+Categories.m in Sources */,
706 733
				B264A22C22B33EB200714D0D /* IPUDatabaseUtil.m in Sources */,
707 734
				B2DB0D70273A6BCB0010074A /* EBBannerViewController.m in Sources */,
735
				76EC0CDC276056A30019B2F5 /* IPUSignViewController.m in Sources */,
708 736
				B29195532539307500AD4C60 /* IPUServiceChangePlugin.m in Sources */,
709 737
				04C30B9B22E6ADF200BA7B68 /* IPUTipsHUDPlugin.m in Sources */,
710 738
				B28E568F21F1A8F500422D15 /* IPUCameraPlugin.m in Sources */,

+ 4 - 3
IPUMobileFunc/IPUMobileFunc/IPUMobileUIPlugin.h

@ -107,8 +107,9 @@
107 107
- (void)tip:(NSArray *)param;
108 108
//alert弹出框
109 109
- (void)alert:(NSArray *)param;
110
//弹出列表选择alert
110
/// 弹出列表选择alert
111 111
- (void)getChoice:(NSArray *)params;
112
113
112
/// 弹出一个签名的界面,返回签名照片的base64字符串
113
/// 如果需要保存到相册,需要添加权限Privacy - Photo Library Additions Usage Description
114
- (void)getSign:(NSArray *)params;
114 115
@end

+ 12 - 0
IPUMobileFunc/IPUMobileFunc/IPUMobileUIPlugin.m

@ -11,6 +11,7 @@
11 11
#import "IPUNetworkPlugin.h"
12 12
#import "IPUNetworkUtil.h"
13 13
#import "IPUDialogUtil.h"
14
#import "IPUSignViewController.h"
14 15
#import <IPUFoundation/IPUFoundation.h>
15 16
#import <IPUMobile/IPUMobile.h>
16 17
#import <IPUMobileUI/IPUMobileUI.h>
@ -817,6 +818,17 @@
817 818
    }];
818 819
}
819 820
821
- (void)getSign:(NSArray *)params {
822
    IPUSignViewController *vc = [[UIStoryboard storyboardWithName:"IPUSignStoryboard" bundle:nil] instantiateInitialViewController];
823
    vc.modalPresentationStyle = UIModalPresentationCustom
824
    vc.saveToPhotos = false;
825
    vc.completion = ^(NSString * _Nonnull base64) {
826
        [self callback: base64];
827
    }
828
    UIViewController *current = [self getViewController];
829
    [current presentViewController:vc animated:true completion:nil];
830
}
831
820 832
#pragma mark - other method
821 833
- (void)clearBackStack:(NSArray *)param {
822 834
    [[self.mobileDelegate getFlipperView] clearBackStack];

+ 1 - 1
IPUMobileFunc/IPUMobileFunc/Implementation/IPUDialogUtil.h

@ -1,6 +1,6 @@
1 1
//
2 2
//  IPUDialogUtil.h
3
//  IPUMobile
3
//  IPUMobileFunc
4 4
//
5 5
//  Created by yang dingli on 2021/12/7.
6 6
//  Copyright © 2021 Asiainfo. All rights reserved.

+ 1 - 1
IPUMobileFunc/IPUMobileFunc/Implementation/IPUDialogUtil.m

@ -1,6 +1,6 @@
1 1
//
2 2
//  IPUDialogUtil.m
3
//  IPUMobile
3
//  IPUMobileFunc
4 4
//
5 5
//  Created by yang dingli on 2021/12/7.
6 6
//  Copyright © 2021 Asiainfo. All rights reserved.

+ 72 - 0
IPUMobileFunc/IPUMobileFunc/Implementation/sign/IPUSignStoryboard.storyboard

@ -0,0 +1,72 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Y6W-OH-hqX">
3
    <device id="retina6_1" orientation="portrait" appearance="light"/>
4
    <dependencies>
5
        <deployment identifier="iOS"/>
6
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
7
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
8
        <capability name="System colors in document resources" minToolsVersion="11.0"/>
9
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10
    </dependencies>
11
    <scenes>
12
        <!--Sign View Controller-->
13
        <scene sceneID="s0d-6b-0kx">
14
            <objects>
15
                <viewController id="Y6W-OH-hqX" customClass="IPUSignViewController" sceneMemberID="viewController">
16
                    <view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc">
17
                        <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
18
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19
                        <subviews>
20
                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="JDQ-qe-blJ" customClass="IPUSignView">
21
                                <rect key="frame" x="0.0" y="44" width="414" height="763"/>
22
                                <color key="backgroundColor" systemColor="systemBackgroundColor"/>
23
                            </view>
24
                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nZ7-Az-xxi">
25
                                <rect key="frame" x="80" y="812" width="80" height="40"/>
26
                                <constraints>
27
                                    <constraint firstAttribute="height" constant="40" id="9Ed-Eu-Rwv"/>
28
                                    <constraint firstAttribute="width" constant="80" id="rYN-Nu-Jsx"/>
29
                                </constraints>
30
                                <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
31
                                <state key="normal" title="Button"/>
32
                            </button>
33
                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fq0-8T-6Eo">
34
                                <rect key="frame" x="254" y="812" width="80" height="40"/>
35
                                <constraints>
36
                                    <constraint firstAttribute="width" constant="80" id="9xs-5q-bxK"/>
37
                                    <constraint firstAttribute="height" constant="40" id="sbr-57-GDl"/>
38
                                </constraints>
39
                                <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
40
                                <state key="normal" title="Button"/>
41
                            </button>
42
                        </subviews>
43
                        <viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/>
44
                        <color key="backgroundColor" systemColor="systemBackgroundColor"/>
45
                        <constraints>
46
                            <constraint firstItem="JDQ-qe-blJ" firstAttribute="top" secondItem="vDu-zF-Fre" secondAttribute="top" id="XrI-J0-biz"/>
47
                            <constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="fq0-8T-6Eo" secondAttribute="trailing" constant="80" id="am9-7w-WM4"/>
48
                            <constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="JDQ-qe-blJ" secondAttribute="trailing" id="cWD-2E-6PR"/>
49
                            <constraint firstItem="vDu-zF-Fre" firstAttribute="bottom" secondItem="JDQ-qe-blJ" secondAttribute="bottom" constant="55" id="ccY-SJ-Z23"/>
50
                            <constraint firstItem="nZ7-Az-xxi" firstAttribute="leading" secondItem="vDu-zF-Fre" secondAttribute="leading" constant="80" id="dNO-d2-hmS"/>
51
                            <constraint firstItem="vDu-zF-Fre" firstAttribute="bottom" secondItem="nZ7-Az-xxi" secondAttribute="bottom" constant="10" id="hVf-iq-PXH"/>
52
                            <constraint firstItem="JDQ-qe-blJ" firstAttribute="leading" secondItem="vDu-zF-Fre" secondAttribute="leading" id="pFJ-rp-u3i"/>
53
                            <constraint firstItem="fq0-8T-6Eo" firstAttribute="centerY" secondItem="nZ7-Az-xxi" secondAttribute="centerY" id="x7e-p8-ce8"/>
54
                        </constraints>
55
                    </view>
56
                    <connections>
57
                        <outlet property="cancelButton" destination="nZ7-Az-xxi" id="fwY-hU-GCo"/>
58
                        <outlet property="confirmButton" destination="fq0-8T-6Eo" id="V6z-aw-p91"/>
59
                        <outlet property="signView" destination="JDQ-qe-blJ" id="xD8-gd-mpB"/>
60
                    </connections>
61
                </viewController>
62
                <placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
63
            </objects>
64
            <point key="canvasLocation" x="132" y="117"/>
65
        </scene>
66
    </scenes>
67
    <resources>
68
        <systemColor name="systemBackgroundColor">
69
            <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
70
        </systemColor>
71
    </resources>
72
</document>

+ 23 - 0
IPUMobileFunc/IPUMobileFunc/Implementation/sign/IPUSignView.h

@ -0,0 +1,23 @@
1
//
2
//  IPUSignView.m
3
//  IPUMobileFunc
4
//
5
//  Created by yang dingli on 2021/12/7.
6
//  Copyright © 2021 Asiainfo. All rights reserved.
7
//
8
9
#import <Foundation/Foundation.h>
10
#import <UIKit/UIKit.h>
11
NS_ASSUME_NONNULL_BEGIN
12
13
IB_DESIGNABLE
14
15
@interface IPUSignView : UIView
16
@property (nonatomic, strong) UIColor *panColor;
17
@property (nonatomic, assign) CGFloat panLineWidth;
18
@property (nonatomic, strong) CAShapeLayer *currentDrawLayer;
19
@property (nonatomic, strong) UIBezierPath *currentDrawPath;
20
@property (nonatomic, strong) NSMutableArray *drawLayerArray;
21
@end
22
23
NS_ASSUME_NONNULL_END

+ 93 - 0
IPUMobileFunc/IPUMobileFunc/Implementation/sign/IPUSignView.m

@ -0,0 +1,93 @@
1
//
2
//  IPUSignView.m
3
//  IPUMobileFunc
4
//
5
//  Created by yang dingli on 2021/12/7.
6
//  Copyright © 2021 Asiainfo. All rights reserved.
7
//
8
9
#import "IPUSignView.h"
10
11
@implementation IPUSignView
12
13
- (instancetype)init {
14
    if (self = [super init]) {
15
        self.backgroundColor = [UIColor whiteColor];
16
        self.panColor = [UIColor blackColor];
17
        self.panLineWidth = 2.f;
18
    }
19
    
20
    return self;
21
}
22
23
- (instancetype)initWithCoder:(NSCoder *)coder {
24
    if (self = [super initWithCoder:coder]) {
25
        self.backgroundColor = [UIColor whiteColor];
26
        self.panColor = [UIColor blackColor];
27
        self.panLineWidth = 2.f;
28
    }
29
    return self;
30
}
31
32
- (instancetype)initWithFrame:(CGRect)frame {
33
    if (self = [super initWithFrame:frame]) {
34
        self.backgroundColor = [UIColor whiteColor];
35
        self.panColor = [UIColor blackColor];
36
        self.panLineWidth = 2.f;
37
    }
38
    return self;
39
}
40
41
- (void)dealloc {
42
    [self releaseAllLayers];
43
}
44
45
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
46
    UITouch *touch = touches.anyObject;
47
    CGPoint startPoint = [touch locationInView:self];
48
    
49
    self.currentDrawLayer = [self makeDrawLayer];
50
    self.currentDrawPath = [self makeDrawPath];
51
    [self.currentDrawPath moveToPoint:startPoint];
52
}
53
54
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
55
    UITouch *touch = touches.anyObject;
56
    CGPoint currentPoint = [touch locationInView:self];
57
    
58
    [self.currentDrawPath addLineToPoint:currentPoint];
59
    self.currentDrawLayer.path = self.currentDrawPath.CGPath;
60
}
61
62
- (NSMutableArray *)drawLayerArray {
63
    if (!_drawLayerArray) {
64
        _drawLayerArray = [NSMutableArray arrayWithCapacity:10];
65
    }
66
    return _drawLayerArray;
67
}
68
69
- (CAShapeLayer *)makeDrawLayer {
70
    CAShapeLayer *drawLayer = [CAShapeLayer layer];
71
    drawLayer.frame = self.bounds;
72
    drawLayer.fillColor = [UIColor clearColor].CGColor;
73
    drawLayer.lineWidth = self.panLineWidth;
74
    drawLayer.strokeColor = self.panColor.CGColor;
75
    [self.layer insertSublayer:drawLayer atIndex:(unsigned)self.drawLayerArray.count];
76
    [self.drawLayerArray addObject:drawLayer];
77
    return drawLayer;
78
}
79
80
- (UIBezierPath *)makeDrawPath {
81
    UIBezierPath *drawPath = [UIBezierPath bezierPath];
82
    drawPath.lineCapStyle = kCGLineCapRound;
83
    drawPath.lineJoinStyle = kCGLineJoinRound;
84
    
85
    return drawPath;
86
}
87
88
- (void)releaseAllLayers {
89
    [self.drawLayerArray makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
90
    [self.drawLayerArray removeAllObjects];
91
}
92
93
@end

+ 21 - 0
IPUMobileFunc/IPUMobileFunc/Implementation/sign/IPUSignViewController.h

@ -0,0 +1,21 @@
1
//
2
//  IPUSignViewController.m
3
//  IPUMobileFunc
4
//
5
//  Created by yang dingli on 2021/12/7.
6
//  Copyright © 2021 Asiainfo. All rights reserved.
7
//
8
9
#import <Foundation/Foundation.h>
10
#import <UIKit/UIKit.h>
11
#import "IPUSignView.h"
12
NS_ASSUME_NONNULL_BEGIN
13
14
typedef void(^IPUSignCompletion)(NSString * base64);
15
16
@interface IPUSignViewController : UIViewController
17
@property (nonatomic, copy) IPUSignCompletion completion;
18
@property (nonatomic, assign) BOOL saveToPhotos;
19
@end
20
21
NS_ASSUME_NONNULL_END

+ 86 - 0
IPUMobileFunc/IPUMobileFunc/Implementation/sign/IPUSignViewController.m

@ -0,0 +1,86 @@
1
//
2
//  IPUSignViewController.m
3
//  IPUMobileFunc
4
//
5
//  Created by yang dingli on 2021/12/7.
6
//  Copyright © 2021 Asiainfo. All rights reserved.
7
//
8
9
#import "IPUSignViewController.h"
10
#import <Photos/Photos.h>
11
12
@interface IPUSignViewController ()
13
@property (weak, nonatomic) IBOutlet IPUSignView *signView;
14
15
@property (weak, nonatomic) IBOutlet UIButton *cancelButton;
16
@property (weak, nonatomic) IBOutlet UIButton *confirmButton;
17
18
@end
19
20
21
@implementation IPUSignViewController
22
23
- (void)loadView {
24
    [super loadView];
25
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
26
}
27
28
- (void)viewDidLoad {
29
    [super viewDidLoad];
30
    self.view.backgroundColor = UIColor.whiteColor;
31
    _cancelButton.layer.cornerRadius = 5;
32
    _cancelButton.layer.masksToBounds = true;
33
    [_cancelButton setBackgroundColor:UIColor.systemBlueColor];
34
    [_cancelButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
35
    [_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
36
    [_cancelButton addTarget:self action:@selector(onCancel:) forControlEvents:UIControlEventTouchUpInside];
37
38
    _confirmButton.layer.cornerRadius = 5;
39
    _confirmButton.layer.masksToBounds = true;
40
    [_confirmButton setBackgroundColor:UIColor.systemBlueColor];
41
    [_confirmButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
42
    [_confirmButton setTitle:@"确定" forState:UIControlStateNormal];
43
    [_confirmButton addTarget:self action:@selector(onConfirm:) forControlEvents:UIControlEventTouchUpInside];
44
}
45
46
- (void)dealloc {
47
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
48
}
49
50
-(void)onConfirm:(UIButton *)sender {
51
    UIImage *image = [self snapshot:self.signView];
52
    if (_completion) {
53
        _completion([self encodeToBase64String:image]);
54
    }
55
    if(_saveToPhotos) {
56
        [self saveImageToPhotos:image];
57
    }
58
    [self dismissViewControllerAnimated:true completion:nil];
59
}
60
61
62
-(void)onCancel:(UIButton *)sender {
63
    [self dismissViewControllerAnimated:true completion:nil];
64
}
65
66
-(void)saveImageToPhotos:(UIImage*)image{
67
    [PHPhotoLibrary.sharedPhotoLibrary performChanges:^{
68
        [PHAssetChangeRequest creationRequestForAssetFromImage: image];
69
    } completionHandler:^(BOOL success, NSError * _Nullable error) {
70
        NSLog(@"save iamge to photos result:%@  error:%@", success ? @"成功" : @"失败", error.localizedDescription);
71
    }];
72
}
73
74
- (UIImage *)snapshot:(UIView *)view {
75
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
76
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
77
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
78
    UIGraphicsEndImageContext();
79
    return image;
80
}
81
82
- (NSString*)encodeToBase64String:(UIImage*)image {
83
    return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
84
}
85
86
@end