Browse Source

添加原生手势锁插件

liufl5 5 years ago
parent
commit
acb4e3a62e

+ 60 - 0
WadeMobileFunc/WadeMobileFunc.xcodeproj/project.pbxproj

@ -40,6 +40,19 @@
40 40
		0429A26121805228003CEE83 /* WDFResourceVersion.h in Headers */ = {isa = PBXBuildFile; fileRef = 0429A25F21805228003CEE83 /* WDFResourceVersion.h */; settings = {ATTRIBUTES = (Public, ); }; };
41 41
		04327F3522F9642400B7670A /* WDFScreenCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = 04327F3322F9642400B7670A /* WDFScreenCapture.h */; settings = {ATTRIBUTES = (Public, ); }; };
42 42
		04327F3622F9642400B7670A /* WDFScreenCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = 04327F3422F9642400B7670A /* WDFScreenCapture.m */; };
43
		043BA1472386765700CBF96B /* CoreConst.h in Headers */ = {isa = PBXBuildFile; fileRef = 043BA13A2386765700CBF96B /* CoreConst.h */; };
44
		043BA1482386765700CBF96B /* CoreLockConst.h in Headers */ = {isa = PBXBuildFile; fileRef = 043BA13B2386765700CBF96B /* CoreLockConst.h */; settings = {ATTRIBUTES = (Public, ); }; };
45
		043BA1492386765700CBF96B /* CLLockView.m in Sources */ = {isa = PBXBuildFile; fileRef = 043BA13C2386765700CBF96B /* CLLockView.m */; };
46
		043BA14A2386765700CBF96B /* CLLockLabel.h in Headers */ = {isa = PBXBuildFile; fileRef = 043BA13D2386765700CBF96B /* CLLockLabel.h */; };
47
		043BA14B2386765700CBF96B /* CALayer+Anim.m in Sources */ = {isa = PBXBuildFile; fileRef = 043BA13E2386765700CBF96B /* CALayer+Anim.m */; };
48
		043BA14D2386765700CBF96B /* CLLockItemView.m in Sources */ = {isa = PBXBuildFile; fileRef = 043BA1402386765700CBF96B /* CLLockItemView.m */; };
49
		043BA14E2386765700CBF96B /* CLLockView.h in Headers */ = {isa = PBXBuildFile; fileRef = 043BA1412386765700CBF96B /* CLLockView.h */; };
50
		043BA14F2386765700CBF96B /* CoreLockConst.m in Sources */ = {isa = PBXBuildFile; fileRef = 043BA1422386765700CBF96B /* CoreLockConst.m */; };
51
		043BA1502386765700CBF96B /* CALayer+Anim.h in Headers */ = {isa = PBXBuildFile; fileRef = 043BA1432386765700CBF96B /* CALayer+Anim.h */; };
52
		043BA1512386765700CBF96B /* CLLockLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 043BA1442386765700CBF96B /* CLLockLabel.m */; };
53
		043BA1522386765700CBF96B /* CLLockItemView.h in Headers */ = {isa = PBXBuildFile; fileRef = 043BA1452386765700CBF96B /* CLLockItemView.h */; };
54
		043BA15723867EA200CBF96B /* CoreLockViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 043BA15523867EA100CBF96B /* CoreLockViewController.m */; };
55
		043BA15823867EA200CBF96B /* CoreLockViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 043BA15623867EA200CBF96B /* CoreLockViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
43 56
		0455D01A224B4DEC006B3F28 /* WDFTipsHUD.h in Headers */ = {isa = PBXBuildFile; fileRef = 0455D018224B4DEC006B3F28 /* WDFTipsHUD.h */; settings = {ATTRIBUTES = (Public, ); }; };
44 57
		0455D01B224B4DEC006B3F28 /* WDFTipsHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 0455D019224B4DEC006B3F28 /* WDFTipsHUD.m */; };
45 58
		0469EA142371633900E1A4D6 /* WDFCustomVideo.h in Headers */ = {isa = PBXBuildFile; fileRef = 0469EA122371633900E1A4D6 /* WDFCustomVideo.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -152,6 +165,19 @@
152 165
		0429A25F21805228003CEE83 /* WDFResourceVersion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WDFResourceVersion.h; sourceTree = "<group>"; };
153 166
		04327F3322F9642400B7670A /* WDFScreenCapture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WDFScreenCapture.h; sourceTree = "<group>"; };
154 167
		04327F3422F9642400B7670A /* WDFScreenCapture.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WDFScreenCapture.m; sourceTree = "<group>"; };
168
		043BA13A2386765700CBF96B /* CoreConst.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreConst.h; sourceTree = "<group>"; };
169
		043BA13B2386765700CBF96B /* CoreLockConst.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreLockConst.h; sourceTree = "<group>"; };
170
		043BA13C2386765700CBF96B /* CLLockView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CLLockView.m; sourceTree = "<group>"; };
171
		043BA13D2386765700CBF96B /* CLLockLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CLLockLabel.h; sourceTree = "<group>"; };
172
		043BA13E2386765700CBF96B /* CALayer+Anim.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CALayer+Anim.m"; sourceTree = "<group>"; };
173
		043BA1402386765700CBF96B /* CLLockItemView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CLLockItemView.m; sourceTree = "<group>"; };
174
		043BA1412386765700CBF96B /* CLLockView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CLLockView.h; sourceTree = "<group>"; };
175
		043BA1422386765700CBF96B /* CoreLockConst.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CoreLockConst.m; sourceTree = "<group>"; };
176
		043BA1432386765700CBF96B /* CALayer+Anim.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CALayer+Anim.h"; sourceTree = "<group>"; };
177
		043BA1442386765700CBF96B /* CLLockLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CLLockLabel.m; sourceTree = "<group>"; };
178
		043BA1452386765700CBF96B /* CLLockItemView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CLLockItemView.h; sourceTree = "<group>"; };
179
		043BA15523867EA100CBF96B /* CoreLockViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CoreLockViewController.m; sourceTree = "<group>"; };
180
		043BA15623867EA200CBF96B /* CoreLockViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreLockViewController.h; sourceTree = "<group>"; };
155 181
		0455D018224B4DEC006B3F28 /* WDFTipsHUD.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WDFTipsHUD.h; sourceTree = "<group>"; };
156 182
		0455D019224B4DEC006B3F28 /* WDFTipsHUD.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WDFTipsHUD.m; sourceTree = "<group>"; };
157 183
		0469EA122371633900E1A4D6 /* WDFCustomVideo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WDFCustomVideo.h; sourceTree = "<group>"; };
@ -280,6 +306,26 @@
280 306
/* End PBXFrameworksBuildPhase section */
281 307
282 308
/* Begin PBXGroup section */
309
		043BA1392386765700CBF96B /* GestureLock */ = {
310
			isa = PBXGroup;
311
			children = (
312
				043BA15623867EA200CBF96B /* CoreLockViewController.h */,
313
				043BA15523867EA100CBF96B /* CoreLockViewController.m */,
314
				043BA13A2386765700CBF96B /* CoreConst.h */,
315
				043BA13B2386765700CBF96B /* CoreLockConst.h */,
316
				043BA1422386765700CBF96B /* CoreLockConst.m */,
317
				043BA1412386765700CBF96B /* CLLockView.h */,
318
				043BA13C2386765700CBF96B /* CLLockView.m */,
319
				043BA1432386765700CBF96B /* CALayer+Anim.h */,
320
				043BA13E2386765700CBF96B /* CALayer+Anim.m */,
321
				043BA13D2386765700CBF96B /* CLLockLabel.h */,
322
				043BA1442386765700CBF96B /* CLLockLabel.m */,
323
				043BA1452386765700CBF96B /* CLLockItemView.h */,
324
				043BA1402386765700CBF96B /* CLLockItemView.m */,
325
			);
326
			path = GestureLock;
327
			sourceTree = "<group>";
328
		};
283 329
		0469EA11237162E100E1A4D6 /* customVideo */ = {
284 330
			isa = PBXGroup;
285 331
			children = (
@ -342,6 +388,7 @@
342 388
		E2DE1AD61B42DD9500762141 /* WadeMobileFunc */ = {
343 389
			isa = PBXGroup;
344 390
			children = (
391
				043BA1392386765700CBF96B /* GestureLock */,
345 392
				0469EA11237162E100E1A4D6 /* customVideo */,
346 393
				0AE1E0721C7EABA700FCCD24 /* util */,
347 394
				EA81E6E51BB3973F0006F354 /* camera */,
@ -477,11 +524,14 @@
477 524
			isa = PBXHeadersBuildPhase;
478 525
			buildActionMask = 2147483647;
479 526
			files = (
527
				043BA1482386765700CBF96B /* CoreLockConst.h in Headers */,
528
				043BA15823867EA200CBF96B /* CoreLockViewController.h in Headers */,
480 529
				0469EA182371668000E1A4D6 /* CustomVideoViewController.h in Headers */,
481 530
				0469EA142371633900E1A4D6 /* WDFCustomVideo.h in Headers */,
482 531
				04327F3522F9642400B7670A /* WDFScreenCapture.h in Headers */,
483 532
				04B7AB5D22FBCE57009B6449 /* IPUGrayPlugin.h in Headers */,
484 533
				0455D01A224B4DEC006B3F28 /* WDFTipsHUD.h in Headers */,
534
				043BA14E2386765700CBF96B /* CLLockView.h in Headers */,
485 535
				B2E8BEB82175D89700A06A13 /* ImageDetailViewController.h in Headers */,
486 536
				B2E8BEBA2175D89700A06A13 /* WDFCustomCamera.h in Headers */,
487 537
				B2E8BEB92175D89700A06A13 /* UIImage+Rotate.h in Headers */,
@ -492,13 +542,17 @@
492 542
				B2E8BEC22175D89700A06A13 /* WDFImagePickerController.h in Headers */,
493 543
				046DC4F1211D21BC00BCA3F5 /* WDFImageCache.h in Headers */,
494 544
				0ABBF2C01F4A90A0009C5E4E /* WDFMobileMail.h in Headers */,
545
				043BA14A2386765700CBF96B /* CLLockLabel.h in Headers */,
546
				043BA1522386765700CBF96B /* CLLockItemView.h in Headers */,
495 547
				E2D30F021C8C45060040A850 /* WDFUNIRestUtil.h in Headers */,
496 548
				0A96AB011B9FCCE8003CACA5 /* WDFMobileDatabase.h in Headers */,
549
				043BA1472386765700CBF96B /* CoreConst.h in Headers */,
497 550
				0AE1E0791C7EABA700FCCD24 /* WDFAFNetworkingUtil.h in Headers */,
498 551
				01FC20812007700C00FA8B40 /* WDFSocial.h in Headers */,
499 552
				01FC20802007700C00FA8B40 /* WDFSocialUtils.h in Headers */,
500 553
				EA81E79C1BB426E00006F354 /* WDFUploadDownload.h in Headers */,
501 554
				0AE1E0771C7EABA700FCCD24 /* WDFDatabaseHelper.h in Headers */,
555
				043BA1502386765700CBF96B /* CALayer+Anim.h in Headers */,
502 556
				E2DE1B0B1B42DE6A00762141 /* WDFMobileCamera.h in Headers */,
503 557
				E2DE1B071B42DE6A00762141 /* WDFMobileAudio.h in Headers */,
504 558
				0A0A235D1CACB92100947564 /* WDFMobileContacts.h in Headers */,
@ -682,10 +736,12 @@
682 736
				E2DE1B101B42DE6A00762141 /* WDFMobileLocation.m in Sources */,
683 737
				B2E8BEBF2175D89700A06A13 /* WDFActionSheet.m in Sources */,
684 738
				E2DE1B121B42DE6A00762141 /* WDFMobileNetwork.m in Sources */,
739
				043BA14F2386765700CBF96B /* CoreLockConst.m in Sources */,
685 740
				E2DE1B161B42DE6A00762141 /* WDFMobileUI.m in Sources */,
686 741
				B2E8BEBB2175D89700A06A13 /* ImageDetailViewController.m in Sources */,
687 742
				0429A26021805228003CEE83 /* WDFResourceVersion.m in Sources */,
688 743
				04B7AB5E22FBCE57009B6449 /* IPUGrayPlugin.m in Sources */,
744
				043BA1512386765700CBF96B /* CLLockLabel.m in Sources */,
689 745
				0AE1E0781C7EABA700FCCD24 /* WDFDatabaseHelper.m in Sources */,
690 746
				E2D30F031C8C45060040A850 /* WDFUNIRestUtil.m in Sources */,
691 747
				E2DE1B0A1B42DE6A00762141 /* WDFMobileBasic.m in Sources */,
@ -693,8 +749,10 @@
693 749
				E2DE1B081B42DE6A00762141 /* WDFMobileAudio.m in Sources */,
694 750
				B2E8BEB72175D89700A06A13 /* CustomCameraViewController.m in Sources */,
695 751
				0A96AB021B9FCCE8003CACA5 /* WDFMobileDatabase.m in Sources */,
752
				043BA15723867EA200CBF96B /* CoreLockViewController.m in Sources */,
696 753
				E2DE1B0C1B42DE6A00762141 /* WDFMobileCamera.m in Sources */,
697 754
				B2E8BEBE2175D89700A06A13 /* UIImage+Rotate.m in Sources */,
755
				043BA1492386765700CBF96B /* CLLockView.m in Sources */,
698 756
				04327F3622F9642400B7670A /* WDFScreenCapture.m in Sources */,
699 757
				01FC207E2007700C00FA8B40 /* WDFSocial.m in Sources */,
700 758
				B2E8BEC12175D89700A06A13 /* WDFImagePickerController.m in Sources */,
@ -702,6 +760,8 @@
702 760
				B2E8BEBD2175D89700A06A13 /* WDFCustomCamera.m in Sources */,
703 761
				0AE1E07A1C7EABA700FCCD24 /* WDFAFNetworkingUtil.m in Sources */,
704 762
				0ABBF2C11F4A90A0009C5E4E /* WDFMobileMail.m in Sources */,
763
				043BA14B2386765700CBF96B /* CALayer+Anim.m in Sources */,
764
				043BA14D2386765700CBF96B /* CLLockItemView.m in Sources */,
705 765
				E2DE1B0E1B42DE6A00762141 /* WDFMobileFile.m in Sources */,
706 766
				B2ADA42A2186DEDB00F0E722 /* IpuAuthentication.m in Sources */,
707 767
				046DC4F2211D21BC00BCA3F5 /* WDFImageCache.m in Sources */,

+ 4 - 4
WadeMobileFunc/WadeMobileFunc.xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@ -26,12 +26,12 @@
26 26
                  moduleName = "WadeMobileFunc"
27 27
                  usesParentBreakpointCondition = "Yes"
28 28
                  urlString = "file:///Users/mac/work/asiainfo/ios-share/WadeMobileFunc/WadeMobileFunc/WDFSocial.m"
29
                  timestampString = "596006670.255143"
29
                  timestampString = "596019995.71078"
30 30
                  startingColumnNumber = "9223372036854775807"
31 31
                  endingColumnNumber = "9223372036854775807"
32 32
                  startingLineNumber = "291"
33 33
                  endingLineNumber = "291"
34
                  offsetFromSymbolStart = "1132">
34
                  offsetFromSymbolStart = "1172">
35 35
               </Location>
36 36
               <Location
37 37
                  shouldBeEnabled = "Yes"
@ -41,12 +41,12 @@
41 41
                  moduleName = "WadeMobileFunc"
42 42
                  usesParentBreakpointCondition = "Yes"
43 43
                  urlString = "file:///Users/mac/work/asiainfo/ios-share/WadeMobileFunc/WadeMobileFunc/WDFSocial.m"
44
                  timestampString = "596006670.2569979"
44
                  timestampString = "596019995.712764"
45 45
                  startingColumnNumber = "9223372036854775807"
46 46
                  endingColumnNumber = "9223372036854775807"
47 47
                  startingLineNumber = "292"
48 48
                  endingLineNumber = "292"
49
                  offsetFromSymbolStart = "52">
49
                  offsetFromSymbolStart = "38">
50 50
               </Location>
51 51
            </Locations>
52 52
         </BreakpointContent>

+ 23 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CALayer+Anim.h

@ -0,0 +1,23 @@
1
//
2
//  CALayer+Anim.h
3
//  CoreLock
4
//
5
//  Created by 冯成林 on 15/4/28.
6
//  Copyright (c) 2015年 冯成林. All rights reserved.
7
//
8
9
#import <QuartzCore/QuartzCore.h>
10
11
@interface CALayer (Anim)
12
13
14
15
/*
16
 *  摇动
17
 */
18
-(void)shake;
19
20
21
22
23
@end

+ 37 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CALayer+Anim.m

@ -0,0 +1,37 @@
1
//
2
//  CALayer+Anim.m
3
//  CoreLock
4
//
5
//  Created by 冯成林 on 15/4/28.
6
//  Copyright (c) 2015年 冯成林. All rights reserved.
7
//
8
9
#import "CALayer+Anim.h"
10
11
@implementation CALayer (Anim)
12
13
14
/*
15
 *  摇动
16
 */
17
-(void)shake{
18
    
19
    CAKeyframeAnimation *kfa = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
20
    
21
    CGFloat s = 16;
22
    
23
    kfa.values = @[@(-s),@(0),@(s),@(0),@(-s),@(0),@(s),@(0)];
24
    
25
    //时长
26
    kfa.duration = .1f;
27
    
28
    //重复
29
    kfa.repeatCount =2;
30
    
31
    //移除
32
    kfa.removedOnCompletion = YES;
33
    
34
    [self addAnimation:kfa forKey:@"shake"];
35
}
36
37
@end

+ 67 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CLLockItemView.h

@ -0,0 +1,67 @@
1
//
2
//  CLLockItemView.h
3
//  CoreLock
4
//
5
//  Created by 成林 on 15/4/21.
6
//  Copyright (c) 2015年 冯成林. All rights reserved.
7
//
8
9
#import <UIKit/UIKit.h>
10
11
12
typedef enum {
13
    
14
    //正上
15
    LockItemViewDirecTop=1,
16
    
17
    //右上
18
    LockItemViewDirecRightTop,
19
    
20
    //右
21
    LockItemViewDirecRight,
22
    
23
    //右下
24
    LockItemViewDiretRightBottom,
25
    
26
    //下
27
    LockItemViewDirecBottom,
28
    
29
    //左下
30
    LockItemViewDirecLeftBottom,
31
    
32
    //左
33
    LockItemViewDirecLeft,
34
    
35
    //左上
36
    LockItemViewDirecLeftTop,
37
38
}LockItemViewDirect;
39
40
41
42
43
@interface CLLockItemView : UIView
44
{
45
    
46
}
47
/** 圆环rect */
48
@property (nonatomic,assign) CGRect calRect;
49
50
/** 选中的rect:大 */
51
@property (nonatomic,assign) CGRect selectedRect1;
52
/** 选中的rect:小 */
53
@property (nonatomic,assign) CGRect selectedRect2;
54
55
/** 角度 */
56
@property (nonatomic,assign) CGFloat angle;
57
58
/** 是否选中 */
59
@property (nonatomic,assign) BOOL selected;
60
61
/** 方向 */
62
@property (nonatomic,assign) LockItemViewDirect direct;
63
64
65
66
67
@end

+ 280 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CLLockItemView.m

@ -0,0 +1,280 @@
1
//
2
//  CLLockItemView.m
3
//  CoreLock
4
//
5
//  Created by 成林 on 15/4/21.
6
//  Copyright (c) 2015年 冯成林. All rights reserved.
7
//
8
9
#import "CLLockItemView.h"
10
#import "CoreLockConst.h"
11
12
@interface CLLockItemView ()
13
14
@end
15
16
17
@implementation CLLockItemView
18
19
-(instancetype)initWithFrame:(CGRect)frame{
20
    self = [super initWithFrame:frame];
21
    if(self){
22
         self.backgroundColor = [UIColor clearColor];
23
    }
24
    return self;
25
}
26
27
-(void)drawRect:(CGRect)rect{
28
    //获取上下文
29
    CGContextRef ctx = UIGraphicsGetCurrentContext();
30
    
31
    //上下文旋转
32
    [self transFormCtx:ctx rect:rect];
33
    
34
    //上下文属性设置
35
    [self propertySetting:ctx];
36
    
37
    //外环:普通
38
    [self circleNormal:ctx rect:rect];
39
    
40
    //选中情况下,绘制背景色
41
    if(_selected){
42
        
43
        //外环大:选中
44
        [self circleSelected1:ctx rect:rect];
45
        
46
        //外环小:选中
47
        [self circleSelected2:ctx rect:rect];
48
        
49
        //三角形:方向标识
50
        [self directFlag:ctx rect:rect];
51
    }
52
}
53
54
55
/*
56
 *  上下文旋转
57
 */
58
-(void)transFormCtx:(CGContextRef)ctx rect:(CGRect)rect{
59
    
60
    if(self.direct == 0) return;
61
    
62
    CGFloat translateXY = rect.size.width * .5f;
63
    
64
    //平移
65
    CGContextTranslateCTM(ctx, translateXY, translateXY);
66
    
67
    CGContextRotateCTM(ctx, self.angle);
68
    
69
    //再平移回来
70
    CGContextTranslateCTM(ctx, -translateXY, -translateXY);
71
}
72
73
74
75
/*
76
 *  三角形:方向标识
77
 */
78
-(void)directFlag:(CGContextRef)ctx rect:(CGRect)rect{
79
    
80
    if(self.direct == 0) return;
81
    
82
    //新建路径:三角形
83
    CGMutablePathRef trianglePathM = CGPathCreateMutable();
84
    
85
    CGFloat marginSelectedCirclev = 4.0f;
86
    CGFloat w =8.0f;
87
    CGFloat h =5.0f;
88
    CGFloat topX = rect.origin.x + rect.size.width * .5f;
89
    CGFloat topY = rect.origin.y +(rect.size.width *.5f - h - marginSelectedCirclev - self.selectedRect2.size.height *.5f);
90
    
91
    CGPathMoveToPoint(trianglePathM, NULL, topX, topY);
92
    
93
    //添加左边点
94
    CGFloat leftPointX = topX - w *.5f;
95
    CGFloat leftPointY =topY + h;
96
    CGPathAddLineToPoint(trianglePathM, NULL, leftPointX, leftPointY);
97
    
98
    //右边的点
99
    CGFloat rightPointX = topX + w *.5f;
100
    CGPathAddLineToPoint(trianglePathM, NULL, rightPointX, leftPointY);
101
102
    //将路径添加到上下文中
103
    CGContextAddPath(ctx, trianglePathM);
104
    
105
    //绘制圆环
106
    CGContextFillPath(ctx);
107
    
108
    //释放路径
109
    CGPathRelease(trianglePathM);
110
}
111
112
113
114
115
/*
116
 *  上下文属性设置
117
 */
118
-(void)propertySetting:(CGContextRef)ctx{
119
    
120
    //设置线宽
121
    CGContextSetLineWidth(ctx, CoreLockArcLineW);
122
    
123
    //设置颜色
124
    UIColor *color = nil;
125
    if(_selected){
126
        color = CoreLockCircleLineSelectedColor;
127
    }else{
128
        color = CoreLockCircleLineNormalColor;
129
    }
130
    [color set];
131
}
132
133
134
135
/*
136
 *  外环:普通
137
 */
138
-(void)circleNormal:(CGContextRef)ctx rect:(CGRect)rect{
139
    
140
    //新建路径:外环
141
    CGMutablePathRef loopPath = CGPathCreateMutable();
142
    
143
    //添加一个圆环路径
144
    CGRect calRect = self.calRect;
145
    CGPathAddEllipseInRect(loopPath, NULL, calRect);
146
    
147
    //将路径添加到上下文中
148
    CGContextAddPath(ctx, loopPath);
149
    
150
    //绘制圆环
151
    CGContextStrokePath(ctx);
152
    
153
    //释放路径
154
    CGPathRelease(loopPath);
155
}
156
157
/*
158
 *  外环大:选中
159
 */
160
-(void)circleSelected1:(CGContextRef)ctx rect:(CGRect)rect{
161
    
162
    //新建路径:外环
163
    CGMutablePathRef circlePath = CGPathCreateMutable();
164
    
165
    //绘制一个圆形
166
    CGPathAddEllipseInRect(circlePath, NULL, self.selectedRect1);
167
    
168
    [CoreLockCircleLineSelectedCircleColor1 set];
169
    
170
    //将路径添加到上下文中
171
    CGContextAddPath(ctx, circlePath);
172
    
173
    //绘制圆环
174
    CGContextFillPath(ctx);
175
    
176
    //释放路径
177
    CGPathRelease(circlePath);
178
}
179
180
181
/*
182
 *  外环小:选中
183
 */
184
-(void)circleSelected2:(CGContextRef)ctx rect:(CGRect)rect{
185
    
186
    //新建路径:外环
187
    CGMutablePathRef circlePath = CGPathCreateMutable();
188
    
189
    //绘制一个圆形
190
    CGPathAddEllipseInRect(circlePath, NULL, self.selectedRect2);
191
    
192
    [CoreLockCircleLineSelectedCircleColor2 set];
193
    
194
    //将路径添加到上下文中
195
    CGContextAddPath(ctx, circlePath);
196
    
197
    //绘制圆环
198
    CGContextFillPath(ctx);
199
    
200
    //释放路径
201
    CGPathRelease(circlePath);
202
}
203
204
205
206
207
208
209
-(void)setSelected:(BOOL)selected{
210
    
211
    _selected = selected;
212
    
213
    [self setNeedsDisplay];
214
}
215
216
217
-(CGRect)calRect{
218
    
219
    if(CGRectEqualToRect(_calRect, CGRectZero)){
220
        
221
        CGFloat lineW =CoreLockArcLineW;
222
        
223
        CGFloat sizeWH = self.bounds.size.width - lineW;
224
        CGFloat originXY = lineW *.5f;
225
        
226
        //添加一个圆环路径
227
        _calRect = (CGRect){CGPointMake(originXY, originXY),CGSizeMake(sizeWH, sizeWH)};
228
//        NSLog(@"self.calRect--------------(%f,%f,%f,%f)",originXY,originXY,sizeWH,sizeWH);
229
    }
230
    
231
    return _calRect;
232
}
233
234
235
236
-(CGRect)selectedRect1{
237
    
238
    if(CGRectEqualToRect(_selectedRect1, CGRectZero)){
239
        
240
        CGRect rect = self.bounds;
241
        
242
        CGFloat selectRectWH = rect.size.width * CoreLockArcWHR1;
243
        
244
        CGFloat selectRectXY = rect.size.width * (1 - CoreLockArcWHR1) *.5f;
245
        
246
        _selectedRect1 = CGRectMake(selectRectXY, selectRectXY, selectRectWH, selectRectWH);
247
        NSLog(@"self.selectedRect1-----------(%f,%f,%f,%f)",selectRectXY,selectRectXY,selectRectWH,selectRectWH);
248
    }
249
    
250
    return _selectedRect1;
251
}
252
253
-(CGRect)selectedRect2{
254
    
255
    if(CGRectEqualToRect(_selectedRect2, CGRectZero)){
256
        
257
        CGRect rect = self.bounds;
258
        
259
        CGFloat selectRectWH = rect.size.width * CoreLockArcWHR2;
260
        
261
        CGFloat selectRectXY = rect.size.width * (1 - CoreLockArcWHR2) *.5f;
262
        
263
        _selectedRect2 = CGRectMake(selectRectXY, selectRectXY, selectRectWH, selectRectWH);
264
        NSLog(@"self.selectedRect2-----------(%f,%f,%f,%f)",selectRectXY,selectRectXY,selectRectWH,selectRectWH);
265
    }
266
    
267
    return _selectedRect2;
268
}
269
270
-(void)setDirect:(LockItemViewDirect)direct{
271
    
272
    _direct = direct;
273
    
274
    self.angle = M_PI_4 * (direct -1);
275
    
276
    [self setNeedsDisplay];
277
}
278
279
280
@end

+ 28 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CLLockLabel.h

@ -0,0 +1,28 @@
1
//
2
//  CLLockLabel.h
3
//  CoreLock
4
//
5
//  Created by 成林 on 15/4/27.
6
//  Copyright (c) 2015年 冯成林. All rights reserved.
7
//
8
9
#import <UIKit/UIKit.h>
10
11
@interface CLLockLabel : UILabel
12
13
14
15
/*
16
 *  普通提示信息
17
 */
18
-(void)showNormalMsg:(NSString *)msg;
19
20
21
22
/*
23
 *  警示信息
24
 */
25
-(void)showWarnMsg:(NSString *)msg;
26
27
28
@end

+ 83 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CLLockLabel.m

@ -0,0 +1,83 @@
1
//
2
//  CLLockLabel.m
3
//  CoreLock
4
//
5
//  Created by 成林 on 15/4/27.
6
//  Copyright (c) 2015年 冯成林. All rights reserved.
7
//
8
9
#import "CLLockLabel.h"
10
#import "CoreLockConst.h"
11
#import "CALayer+Anim.h"
12
13
@implementation CLLockLabel
14
15
16
17
18
-(instancetype)initWithFrame:(CGRect)frame{
19
    
20
    self = [super initWithFrame:frame];
21
    
22
    if(self){
23
        self.backgroundColor = [UIColor clearColor];
24
        //视图初始化
25
        [self viewPrepare];
26
    }
27
    
28
    return self;
29
}
30
31
32
33
-(id)initWithCoder:(NSCoder *)aDecoder{
34
    
35
    self=[super initWithCoder:aDecoder];
36
    
37
    if(self){
38
        self.backgroundColor = [UIColor clearColor];
39
        //视图初始化
40
        [self viewPrepare];
41
    }
42
    
43
    return self;
44
}
45
46
47
/*
48
 *  视图初始化
49
 */
50
-(void)viewPrepare{
51
    
52
    self.font = [UIFont systemFontOfSize:16.0f];
53
}
54
55
56
57
58
59
/*
60
 *  普通提示信息
61
 */
62
-(void)showNormalMsg:(NSString *)msg{
63
    
64
    self.text = msg;
65
    self.textColor = CoreLockBlackColor;
66
}
67
68
69
70
/*
71
 *  警示信息
72
 */
73
-(void)showWarnMsg:(NSString *)msg{
74
    
75
    self.text = msg;
76
    self.textColor = CoreLockWarnColor;
77
    
78
    //添加一个shake动画
79
    [self.layer shake];
80
}
81
82
83
@end

+ 71 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CLLockView.h

@ -0,0 +1,71 @@
1
//
2
//  CLLockView.h
3
//  CoreLock
4
//
5
//  Created by 成林 on 15/4/21.
6
//  Copyright (c) 2015年 冯成林. All rights reserved.
7
//
8
9
#import <UIKit/UIKit.h>
10
#import "CoreLockViewController.h"
11
@interface CLLockView : UIView
12
13
@property (nonatomic,assign) CoreLockType type;
14
/*
15
 *  设置密码
16
 */
17
18
/** 开始输入,第一次 */
19
@property (nonatomic,copy) void (^setPWBeginBlock)();
20
21
/** 开始输入,确认密码*/
22
@property (nonatomic,copy) void (^setPWConfirmlock)();
23
24
25
/** 设置密码出错:长度不够 */
26
@property (nonatomic,copy) void (^setPWSErrorLengthTooShortBlock)(NSUInteger currentCount);
27
28
29
/** 设置密码出错:再次密码不一致 */
30
@property (nonatomic,copy) void (^setPWSErrorTwiceDiffBlock)(NSString *pwd1,NSString *pwdNow);
31
32
33
/** 设置密码:第一次输入正确*/
34
@property (nonatomic,copy) void (^setPWFirstRightBlock)();
35
36
37
/** 再次密码输入一致 */
38
@property (nonatomic,copy) void (^setPWTwiceSameBlock)(NSString *pwd);
39
40
41
/*
42
 *  重设密码
43
 */
44
-(void)resetPwd;
45
46
47
/*
48
 *  验证密码
49
 */
50
51
/** 验证密码开始*/
52
@property (nonatomic,copy) void (^verifyPWBeginBlock)();
53
54
/** 验证密码 */
55
@property (nonatomic,copy) BOOL (^verifyPwdBlock)(NSString *pwd);
56
57
58
/*
59
 *  修改密码
60
 */
61
/** 再次密码输入一致 */
62
@property (nonatomic,copy) void (^modifyPwdBlock)();
63
64
65
/** 密码修改成功 */
66
@property (nonatomic,copy) void (^modifyPwdSuccessBlock)();
67
68
69
70
71
@end

+ 496 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CLLockView.m

@ -0,0 +1,496 @@
1
//
2
//  CLLockView.m
3
//  CoreLock
4
//
5
//  Created by 成林 on 15/4/21.
6
//  Copyright (c) 2015年 冯成林. All rights reserved.
7
//
8
9
#import "CLLockView.h"
10
#import "CLLockItemView.h"
11
#import "CoreLockConst.h"
12
13
14
const CGFloat marginValue = 33.0f;//36.0f;
15
16
17
@interface CLLockView ()
18
19
/** 装itemView的可变数组*/
20
@property (nonatomic,strong) NSMutableArray *itemViewsM;
21
22
23
/** 临时密码记录器 */
24
@property (nonatomic,copy) NSMutableString *pwdM;
25
26
27
/** 设置密码:第一次设置的正确的密码 */
28
@property (nonatomic,copy) NSString *firstRightPWD;
29
30
31
/** 修改密码过程中的验证旧密码正确 */
32
@property (nonatomic,assign) BOOL modify_VeriryOldRight;
33
34
35
36
37
@end
38
39
40
41
@implementation CLLockView
42
43
44
-(id)initWithCoder:(NSCoder *)aDecoder{
45
    
46
    self=[super initWithCoder:aDecoder];
47
    
48
    if(self){
49
        
50
        //解锁视图准备
51
        [self lockViewPrepare];
52
    }
53
    
54
    return self;
55
}
56
57
58
59
-(instancetype)initWithFrame:(CGRect)frame{
60
    
61
    self = [super initWithFrame:frame];
62
    
63
    if(self){
64
        
65
        //解锁视图准备
66
        [self lockViewPrepare];
67
    }
68
    
69
    return self;
70
}
71
72
73
/*
74
 *  绘制线条
75
 */
76
-(void)drawRect:(CGRect)rect{
77
    
78
    //数组为空直接返回
79
    if(_itemViewsM == nil || _itemViewsM.count == 0) return;
80
    
81
    //获取上下文
82
    CGContextRef ctx = UIGraphicsGetCurrentContext();
83
    
84
    //添加路径
85
    CGContextAddRect(ctx, rect);
86
    
87
    //添加圆形路径
88
    //遍历所有的itemView
89
    [_itemViewsM enumerateObjectsUsingBlock:^(CLLockItemView *itemView, NSUInteger idx, BOOL *stop) {
90
91
        CGContextAddEllipseInRect(ctx, itemView.frame);
92
    }];
93
    
94
    //剪裁
95
    CGContextEOClip(ctx);
96
    
97
    //新建路径:管理线条
98
    CGMutablePathRef pathM = CGPathCreateMutable();
99
100
    //设置上下文属性
101
    //1.设置线条颜色
102
    [CoreLockLockLineColor set];
103
    
104
    //线条转角样式
105
    CGContextSetLineCap(ctx, kCGLineCapRound);
106
    CGContextSetLineJoin(ctx, kCGLineJoinRound);
107
    
108
    //设置线宽
109
    CGContextSetLineWidth(ctx, 2.0f);
110
    
111
    //遍历所有的itemView
112
    [_itemViewsM enumerateObjectsUsingBlock:^(CLLockItemView *itemView, NSUInteger idx, BOOL *stop) {
113
        
114
        CGPoint directPoint = itemView.center;
115
        
116
        if(idx == 0){//第一个
117
            
118
            //添加起点
119
            CGPathMoveToPoint(pathM, NULL, directPoint.x, directPoint.y);
120
            
121
        }else{//其他
122
            
123
            //添加路径线条
124
            CGPathAddLineToPoint(pathM, NULL, directPoint.x, directPoint.y);
125
        }
126
    }];
127
128
    //将路径添加到上下文
129
    CGContextAddPath(ctx, pathM);
130
    
131
    //渲染路径
132
    CGContextStrokePath(ctx);
133
    
134
    //释放路径
135
    CGPathRelease(pathM);
136
}
137
138
139
140
141
142
143
144
145
146
/*
147
 *  解锁视图准备
148
 */
149
-(void)lockViewPrepare{
150
151
    for (NSUInteger i=0; i<9; i++) {
152
        
153
        CLLockItemView *itemView = [[CLLockItemView alloc] init];
154
        
155
        [self addSubview:itemView];
156
    }
157
}
158
159
160
-(void)layoutSubviews{
161
    
162
    [super layoutSubviews];
163
    
164
    CGFloat itemViewWH = (self.frame.size.width - 4 * marginValue) /3.0f;
165
166
    [self.subviews enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) {
167
        
168
        NSUInteger row = idx % 3;
169
        
170
        NSUInteger col = idx / 3;
171
        
172
        CGFloat x = marginValue * (row +1) + row * itemViewWH;
173
        
174
        CGFloat y =marginValue * (col +1) + col * itemViewWH;
175
        
176
        CGRect frame = CGRectMake(x, y, itemViewWH, itemViewWH);
177
        
178
        //设置tag
179
        subview.tag = idx;
180
        
181
        subview.frame = frame;
182
    }];
183
    
184
}
185
186
187
188
189
190
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
191
    
192
    //解锁处理
193
    [self lockHandle:touches];
194
    
195
196
    if(CoreLockTypeSetPwd == _type){ // 设置密码
197
        //开始
198
        if(self.firstRightPWD == nil){//第一次输入
199
            
200
            if(_setPWBeginBlock != nil) _setPWBeginBlock();
201
            
202
        }else{//确认
203
            
204
            if(_setPWConfirmlock != nil) _setPWConfirmlock();
205
        }
206
    }else if(CoreLockTypeVeryfiPwd == _type){//验证密码
207
        
208
        //开始
209
        if(_verifyPWBeginBlock != nil) _verifyPWBeginBlock();
210
        
211
    }else if (CoreLockTypeModifyPwd == _type){
212
        
213
        //开始
214
        if(_modifyPwdBlock != nil) _modifyPwdBlock();
215
    }
216
}
217
218
219
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
220
    
221
    //解锁处理
222
    [self lockHandle:touches];
223
}
224
225
226
227
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
228
    
229
    //手势结束
230
    [self gestureEnd];
231
}
232
233
234
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
235
 
236
    //手势结束
237
    [self gestureEnd];
238
}
239
240
241
/*
242
 *  手势结束
243
 */
244
-(void)gestureEnd{
245
    
246
247
    //设置密码检查
248
    if(self.pwdM.length != 0){
249
        [self setpwdCheck];
250
    }
251
252
    
253
    for (CLLockItemView *itemView in self.itemViewsM) {
254
        
255
        itemView.selected = NO;
256
        
257
        //清空方向
258
        itemView.direct = 0;
259
    }
260
    
261
    //清空数组所有对象
262
    [self.itemViewsM removeAllObjects];
263
    
264
    //再绘制
265
    [self setNeedsDisplay];
266
    
267
    //清空密码
268
    self.pwdM = nil;
269
270
}
271
272
273
274
/*
275
 *  设置密码检查
276
 */
277
-(void)setpwdCheck{
278
    
279
    NSUInteger count = self.itemViewsM.count;
280
    
281
    if(count < CoreLockMinItemCount){
282
        if(_setPWSErrorLengthTooShortBlock != nil) _setPWSErrorLengthTooShortBlock(count);
283
        return;
284
    }
285
    
286
    if(CoreLockTypeSetPwd == _type){//设置密码
287
        
288
        //设置密码
289
        [self setpwd];
290
        
291
    }else if(CoreLockTypeVeryfiPwd == _type){//验证密码
292
        
293
        if(_verifyPwdBlock != nil) _verifyPwdBlock(self.pwdM);
294
        
295
    }else if (CoreLockTypeModifyPwd == _type){//修改密码
296
        
297
        if(!_modify_VeriryOldRight){
298
            
299
            if(_verifyPwdBlock != nil){
300
                _modify_VeriryOldRight = _verifyPwdBlock(self.pwdM);
301
            }
302
            
303
        }else{
304
            
305
            //设置密码
306
            [self setpwd];
307
        }
308
    }
309
    
310
}
311
312
/*
313
 *  设置密码
314
 */
315
-(void)setpwd{
316
    
317
    //密码合法
318
    if(self.firstRightPWD == nil){// 第一次设置密码
319
        self.firstRightPWD = self.pwdM;
320
        if(_setPWFirstRightBlock != nil) _setPWFirstRightBlock();
321
    }else{
322
        
323
        if(![self.firstRightPWD isEqualToString:self.pwdM]){//两次密码不一致
324
            
325
            if(_setPWSErrorTwiceDiffBlock != nil) _setPWSErrorTwiceDiffBlock(self.firstRightPWD,self.pwdM);
326
            return;
327
            
328
        }else{//再次密码输入一致
329
            
330
            if(_setPWTwiceSameBlock != nil) _setPWTwiceSameBlock(self.firstRightPWD);
331
        }
332
    }
333
334
}
335
336
/*
337
 *  解锁处理
338
 */
339
-(void)lockHandle:(NSSet *)touches{
340
    
341
    //取出触摸点
342
    UITouch *touch = [touches anyObject];
343
    
344
    CGPoint loc = [touch locationInView:self];
345
    
346
    CLLockItemView *itemView = [self itemViewWithTouchLocation:loc];
347
    
348
    //如果为空,返回
349
    if(itemView ==nil) return;
350
    
351
    //如果已经存在,返回
352
    if([self.itemViewsM containsObject:itemView]) return;
353
    
354
    //添加
355
    [self.itemViewsM addObject:itemView];
356
    
357
    //记录密码
358
    [self.pwdM appendFormat:@"%@",@(itemView.tag)];
359
    
360
    
361
    //计算方向:每添加一次itemView就计算一次
362
    [self calDirect];
363
    
364
    //item处理
365
    [self itemHandel:itemView];
366
}
367
368
369
370
/*
371
 *  计算方向:每添加一次itemView就计算一次
372
 */
373
-(void)calDirect{
374
    
375
    NSUInteger count = _itemViewsM.count;
376
    
377
    if(_itemViewsM==nil || count<=1) return;
378
    
379
    //取出最后一个对象
380
    CLLockItemView *last_1_ItemView = _itemViewsM.lastObject;
381
    
382
    //倒数第二个
383
    CLLockItemView *last_2_ItemView =_itemViewsM[count -2];
384
    
385
    //计算倒数第二个的位置
386
    CGFloat last_1_x = last_1_ItemView.frame.origin.x;
387
    CGFloat last_1_y = last_1_ItemView.frame.origin.y;
388
    CGFloat last_2_x = last_2_ItemView.frame.origin.x;
389
    CGFloat last_2_y = last_2_ItemView.frame.origin.y;
390
    
391
    //倒数第一个itemView相对倒数第二个itemView来说
392
    //正上
393
    if(last_2_x == last_1_x && last_2_y > last_1_y) {
394
        last_2_ItemView.direct = LockItemViewDirecTop;
395
    }
396
    
397
    //正左
398
    if(last_2_y == last_1_y && last_2_x > last_1_x) {
399
        last_2_ItemView.direct = LockItemViewDirecLeft;
400
    }
401
    
402
    //正下
403
    if(last_2_x == last_1_x && last_2_y < last_1_y) {
404
        last_2_ItemView.direct = LockItemViewDirecBottom;
405
    }
406
    
407
    //正右
408
    if(last_2_y == last_1_y && last_2_x < last_1_x) {
409
        last_2_ItemView.direct = LockItemViewDirecRight;
410
    }
411
    
412
    //左上
413
    if(last_2_x > last_1_x && last_2_y > last_1_y) {
414
        last_2_ItemView.direct = LockItemViewDirecLeftTop;
415
    }
416
    
417
    //右上
418
    if(last_2_x < last_1_x && last_2_y > last_1_y) {
419
        last_2_ItemView.direct = LockItemViewDirecRightTop;
420
    }
421
    
422
    //左下
423
    if(last_2_x > last_1_x && last_2_y < last_1_y) {
424
        last_2_ItemView.direct = LockItemViewDirecLeftBottom;
425
    }
426
    
427
    //右下
428
    if(last_2_x < last_1_x && last_2_y < last_1_y) {
429
        last_2_ItemView.direct = LockItemViewDiretRightBottom;
430
    }
431
    
432
}
433
434
/*
435
 *  item处理
436
 */
437
-(void)itemHandel:(CLLockItemView *)itemView{
438
    
439
    //选中
440
    itemView.selected = YES;
441
    
442
    //绘制
443
    [self setNeedsDisplay];
444
}
445
446
447
448
-(CLLockItemView *)itemViewWithTouchLocation:(CGPoint)loc{
449
    
450
    CLLockItemView *itemView = nil;
451
    
452
    for (CLLockItemView *itemViewSub in self.subviews) {
453
        
454
        if(!CGRectContainsPoint(itemViewSub.frame, loc)) continue;
455
        itemView = itemViewSub;
456
        break;
457
    }
458
    
459
    return itemView;
460
}
461
462
463
464
465
-(NSMutableArray *)itemViewsM{
466
    
467
    if(_itemViewsM == nil){
468
        
469
        _itemViewsM = [NSMutableArray array];
470
    }
471
    
472
    return _itemViewsM;
473
}
474
475
476
-(NSMutableString *)pwdM{
477
    
478
    if(_pwdM == nil){
479
        
480
        _pwdM = [NSMutableString string];
481
    }
482
    
483
    return _pwdM;
484
}
485
486
487
/*
488
 *  重设密码
489
 */
490
-(void)resetPwd{
491
    
492
    //清空第一次密码即可
493
    self.firstRightPWD = nil;
494
}
495
496
@end

+ 38 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CoreConst.h

@ -0,0 +1,38 @@
1
//全局通用常量定义,结尾请不要使用;号
2
3
4
//ios系统版本
5
#define ios8x [[[UIDevice currentDevice] systemVersion] floatValue] >=8.0f
6
#define ios7x ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) && ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0f)
7
#define ios6x [[[UIDevice currentDevice] systemVersion] floatValue] < 7.0f
8
#define iosNot6x [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f
9
10
11
#define iphone4x_3_5 ([UIScreen mainScreen].bounds.size.height==480.0f)
12
13
#define iphone5x_4_0 ([UIScreen mainScreen].bounds.size.height==568.0f)
14
15
#define iphone6_4_7 ([UIScreen mainScreen].bounds.size.height==667.0f)
16
17
#define iphone6Plus_5_5 ([UIScreen mainScreen].bounds.size.height==736.0f || [UIScreen mainScreen].bounds.size.height==414.0f)
18
19
//屏幕宽高
20
#define kScreenW [[UIScreen mainScreen] bounds].size.width
21
#define kScreenH [[UIScreen mainScreen] bounds].size.height
22
23
//屏幕frame,bounds,size
24
#define kScreenFrame [UIScreen mainScreen].bounds
25
#define kScreenBounds [UIScreen mainScreen].bounds
26
#define kScreenSize [UIScreen mainScreen].bounds.size
27
28
29
30
#define rgb(r,g,b) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:1.0f]
31
#define rgba(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
32
#define hexColor(colorV) [UIColor colorWithHexColorString:@#colorV]
33
#define hexColorAlpha(colorV,a) [UIColor colorWithHexColorString:@#colorV alpha:a];
34
35
36
#define StringFromInteger(i) [NSString stringWithFormat:@"%@",@(i)]
37
38

+ 137 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CoreLockConst.h

@ -0,0 +1,137 @@
1
//
2
//  CoreLockConst.h
3
//  CoreLock
4
//
5
//  Created by 成林 on 15/4/24.
6
//  Copyright (c) 2015年 冯成林. All rights reserved.
7
//
8
9
#import <Foundation/Foundation.h>
10
#import <UIKit/UIKit.h>
11
12
13
#ifndef _CoreLockConst_H_
14
#define _CoreLockConst_H_
15
16
17
#define rgba(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
18
19
20
/*
21
 *  背景色
22
 */ 
23
#define CoreLockViewBgColor rgba(254,255,255,1)//(13,52,89,1)蓝色,(254,255,255,1)白色
24
25
/*
26
 *  外环线条颜色:默认
27
 */
28
#define CoreLockCircleLineNormalColor rgba(109,109,109,1)//(241,241,241,1)白色,(109,109,109,1)深灰色
29
30
31
/*
32
 *  外环线条颜色:选中
33
 */
34
#define CoreLockCircleLineSelectedColor rgba(241,98,69,1)//(34,178,246,1)蓝色,(241,98,69,1)橘色
35
36
37
/*
38
 *  实心圆大:选中
39
 */
40
#define CoreLockCircleLineSelectedCircleColor1 rgba(241,98,69,0.2)//(34,178,246,1)蓝色,(241,98,69,1)橘色
41
42
/*
43
 *  实心圆小:选中
44
 */
45
#define CoreLockCircleLineSelectedCircleColor2 rgba(241,98,69,1)//(34,178,246,1)蓝色,(241,98,69,1)橘色
46
47
48
/*
49
 *  连接线
50
 */
51
#define CoreLockLockLineColor rgba(241,98,69,1)//(34,178,246,1)蓝色,(241,98,69,1)橘色
52
53
54
55
/*
56
 *  警示文字颜色
57
 */
58
#define CoreLockWarnColor rgba(254,82,92,1)
59
60
/*
61
 *  普通文字颜色
62
 */
63
#define CoreLockBlackColor rgba(0,0,0,1)
64
65
66
67
/** 选中圆大小比例:大 */
68
extern const CGFloat CoreLockArcWHR1;
69
70
71
/** 选中圆大小比例:小 */
72
extern const CGFloat CoreLockArcWHR2;
73
74
75
/** 选中圆大小的线宽 */
76
extern const CGFloat CoreLockArcLineW;
77
78
79
/** 密码存储Key */
80
extern NSString *const CoreLockPWDKey;
81
82
83
/** 最低设置密码数目 */
84
extern const NSUInteger CoreLockMinItemCount;
85
86
87
88
/*
89
 *  设置密码
90
 */
91
92
/** 设置密码提示文字:第一次 */
93
extern NSString *const CoreLockPWDTitleFirst;
94
95
96
/** 设置密码提示文字:确认 */
97
extern NSString *const CoreLockPWDTitleConfirm;
98
99
100
/** 设置密码提示文字:再次密码不一致 */
101
extern NSString *const CoreLockPWDDiffTitle;
102
103
104
/** 设置密码提示文字:设置成功 */
105
extern NSString *const CoreLockPWSuccessTitle;
106
107
108
109
/*
110
 *  验证密码
111
 */
112
113
/** 验证密码:普通提示文字 */
114
extern NSString *const CoreLockVerifyNormalTitle;
115
116
117
/** 验证密码:密码错误 */
118
extern NSString *const CoreLockVerifyErrorPwdTitle;
119
120
/*
121
 密码连续输入错误5次,请重新登录
122
 */
123
extern NSString *const CoreLockVerifyFiveErrorPwdTitle;
124
125
/** 验证密码:验证成功 */
126
extern NSString *const CoreLockVerifySuccesslTitle;
127
128
129
130
/*
131
 *  修改密码
132
 */
133
/** 修改密码:普通提示文字 */
134
extern NSString *const CoreLockModifyNormalTitle;
135
extern NSString *const CoreLockModifyTitleFirst;
136
137
#endif

+ 84 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CoreLockConst.m

@ -0,0 +1,84 @@
1
//
2
//  CoreLockConst.m
3
//  CoreLock
4
//
5
//  Created by 成林 on 15/4/24.
6
//  Copyright (c) 2015年 冯成林. All rights reserved.
7
//
8
9
#ifndef _CoreLockConst_H_
10
#define _CoreLockConst_H_
11
12
#import <UIKit/UIKit.h>
13
14
/** 选中圆大小比例:大 */
15
const CGFloat CoreLockArcWHR1 = .86f;
16
17
/** 选中圆大小比例:小 */
18
const CGFloat CoreLockArcWHR2 = .18f;
19
20
21
/** 选中圆大小的线宽 */
22
const CGFloat CoreLockArcLineW = 1.0f;
23
24
25
/** 密码存储Key */
26
NSString *const CoreLockPWDKey = @"CoreLockPWDKey";
27
28
29
/*
30
 *  设置密码
31
 */
32
33
34
/** 最低设置密码数目 */
35
const NSUInteger CoreLockMinItemCount = 4;
36
37
38
/** 设置密码提示文字 */
39
NSString *const CoreLockPWDTitleFirst = @"请滑动设置手势密码";
40
41
42
43
/** 设置密码提示文字:确认 */
44
NSString *const CoreLockPWDTitleConfirm = @"请再次输入确认密码";
45
46
47
/** 设置密码提示文字:再次密码不一致 */
48
NSString *const CoreLockPWDDiffTitle = @"再次密码输入不一致";
49
50
/** 设置密码提示文字:设置成功 */
51
NSString *const CoreLockPWSuccessTitle = @"密码设置成功!";
52
53
54
/*
55
 *  验证密码
56
 */
57
58
/** 验证密码:普通提示文字 */
59
NSString *const CoreLockVerifyNormalTitle = @"请滑动输入密码";
60
61
62
/** 验证密码:密码错误 */
63
NSString *const CoreLockVerifyErrorPwdTitle = @"输入密码错误";
64
65
/*
66
 密码连续输入错误5次,请重新登录
67
 */
68
NSString *const CoreLockVerifyFiveErrorPwdTitle = @"密码连续输入错误5次,请重新登录";
69
70
71
/** 验证密码:验证成功 */
72
NSString *const CoreLockVerifySuccesslTitle = @"密码正确";
73
74
75
/*
76
 *  修改密码
77
 */
78
/** 修改密码:普通提示文字 */
79
NSString *const CoreLockModifyNormalTitle = @"请输入旧密码";
80
NSString *const CoreLockModifyTitleFirst = @"请滑动设置新密码";
81
82
83
84
#endif

+ 74 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CoreLockViewController.h

@ -0,0 +1,74 @@
1
//
2
//  GesturePasswordViewController.h
3
//  paycoffee
4
//
5
//  Created by 刘方丽 on 15/5/5.
6
//  Copyright (c) 2015年 lfl. All rights reserved.
7
//
8
9
#import <UIKit/UIKit.h>
10
@class CLLockView;
11
@class CLLockLabel;
12
13
typedef NS_ENUM(NSInteger, CoreLockType) {
14
    //设置密码
15
    CoreLockTypeSetPwd,
16
    
17
    //输入并验证密码
18
    CoreLockTypeVeryfiPwd,
19
    
20
    //修改密码
21
    CoreLockTypeModifyPwd,
22
};
23
24
25
/*
26
 系统中用到的手势调用类
27
 */
28
@interface CoreLockViewController : UIViewController
29
{
30
    
31
}
32
33
@property(nonatomic,assign)CoreLockType type;//手势类型:设置密码、修改密码、验证密码
34
35
/** 操作成功:密码设置成功、密码验证成功 */
36
@property (nonatomic,copy) void (^successBlock)(CoreLockViewController *lockVC,NSString *pwd);
37
@property (nonatomic,copy) void (^forgetPwdBlock)();
38
@property (nonatomic,copy) NSString * msg;
39
@property (nonatomic,copy) NSString * modifyCurrentTitle;
40
/** 直接进入修改页面的 */
41
@property (nonatomic,assign) BOOL isDirectModify;
42
43
@property (nonatomic,weak) UIViewController * vc;//手势控制器
44
@property (nonatomic,weak) CLLockView * lockView;//手势视图
45
@property (nonatomic,weak) CLLockLabel * label;//用于显示提示信息
46
@property (nonatomic,strong) UIBarButtonItem * resetItem;//重置按钮
47
@property (nonatomic,strong) UIBarButtonItem * updateItem;//修改密码按钮
48
@property (nonatomic,strong) UIBarButtonItem * closeItem;//关闭按钮
49
50
51
/*
52
 *  展示设置密码控制器
53
 */
54
+(instancetype)showSettingLockVCInVC:(UIViewController *)vc successBlock:(void(^)(CoreLockViewController *lockVC, NSString *pwd))successBlock;
55
56
57
/*
58
 *  展示验证密码输入框
59
 */
60
+(instancetype)showVerifyLockVCInVC:(UIViewController *)vc forgetPwdBlock:(void(^)())forgetPwdBlock successBlock:(void(^)(CoreLockViewController *lockVC, NSString *pwd))successBlock;
61
62
63
/*
64
 *  展示修改密码输入框
65
 */
66
+(instancetype)showModifyLockVCInVC:(UIViewController *)vc successBlock:(void(^)(CoreLockViewController *lockVC, NSString *pwd))successBlock;
67
68
69
/*
70
 *  消失
71
 */
72
-(void)dismiss:(NSTimeInterval)interval;
73
74
@end

+ 426 - 0
WadeMobileFunc/WadeMobileFunc/GestureLock/CoreLockViewController.m

@ -0,0 +1,426 @@
1
//
2
//  GesturePasswordViewController.m
3
//  paycoffee
4
//
5
//  Created by 刘方丽 on 15/5/5.
6
//  Copyright (c) 2015年 lfl. All rights reserved.
7
//
8
9
#import "CoreLockViewController.h"
10
#import "CoreLockConst.h"
11
#import "CoreConst.h"
12
#import "CLLockLabel.h"
13
#import "CLLockView.h"
14
15
#define lockViewWidth (kScreenW-40)
16
17
@interface CoreLockViewController ()
18
19
@end
20
21
@implementation CoreLockViewController
22
23
- (void)viewDidLoad {
24
    [super viewDidLoad];
25
    [self vcPrepare];
26
    [self dataTransfer];
27
    [self event];
28
}
29
30
/*
31
 *  事件
32
 */
33
-(void)event{
34
    
35
    
36
    /*
37
     *  设置密码
38
     */
39
    
40
    /** 开始输入:第一次 */
41
    self.lockView.setPWBeginBlock = ^(){
42
        
43
        [self.label showNormalMsg:CoreLockPWDTitleFirst];
44
    };
45
    
46
    /** 开始输入:确认 */
47
    self.lockView.setPWConfirmlock = ^(){
48
        
49
        [self.label showNormalMsg:CoreLockPWDTitleConfirm];
50
    };
51
    
52
    
53
    /** 密码长度不够 */
54
    self.lockView.setPWSErrorLengthTooShortBlock = ^(NSUInteger currentCount){
55
        
56
        [self.label showWarnMsg:[NSString stringWithFormat:@"请连接至少%@个点",@(CoreLockMinItemCount)]];
57
    };
58
    
59
    /** 两次密码不一致 */
60
    self.lockView.setPWSErrorTwiceDiffBlock = ^(NSString *pwd1,NSString *pwdNow){
61
        [self.label showWarnMsg:CoreLockPWDDiffTitle];
62
        self.navigationItem.rightBarButtonItem = self.resetItem;
63
    };
64
    
65
    /** 第一次输入密码:正确 */
66
    self.lockView.setPWFirstRightBlock = ^(){
67
        
68
        [self.label showNormalMsg:CoreLockPWDTitleConfirm];
69
    };
70
    
71
    /** 再次输入密码一致 */
72
    self.lockView.setPWTwiceSameBlock = ^(NSString *pwd){
73
        
74
        [self.label showNormalMsg:CoreLockPWSuccessTitle];
75
        
76
        //存储密码
77
        NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
78
        [defaults setObject:pwd forKey:CoreLockPWDKey];
79
        [defaults synchronize];
80
        
81
        //禁用交互
82
        self.view.userInteractionEnabled = NO;
83
        
84
        if(_successBlock != nil) _successBlock(self,pwd);
85
        
86
        if(CoreLockTypeModifyPwd == _type){
87
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
88
                [self.navigationController popViewControllerAnimated:YES];
89
            });
90
        }
91
    };
92
    
93
    
94
    
95
    /*
96
     *  验证密码
97
     */
98
    
99
    /** 开始 */
100
    self.lockView.verifyPWBeginBlock = ^(){
101
        
102
        [self.label showNormalMsg:CoreLockVerifyNormalTitle];
103
    };
104
    
105
    /** 验证 */
106
    self.lockView.verifyPwdBlock = ^(NSString *pwd){
107
        
108
        //取出本地密码
109
        NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
110
        NSString *pwdLocal = (NSString *)[defaults objectForKey:CoreLockPWDKey];
111
        
112
        BOOL res = [pwdLocal isEqualToString:pwd];
113
        
114
        if(res){//密码一致
115
            
116
            [self.label showNormalMsg:CoreLockVerifySuccesslTitle];
117
            
118
            if(CoreLockTypeVeryfiPwd == _type){
119
                
120
                //禁用交互
121
                self.view.userInteractionEnabled = NO;
122
                
123
            }
124
            else if (CoreLockTypeModifyPwd == _type){//修改密码
125
                
126
                [self.label showNormalMsg:CoreLockModifyTitleFirst];
127
                
128
            }
129
            if(CoreLockTypeVeryfiPwd == _type) {
130
                if(_successBlock != nil) _successBlock(self,pwd);
131
            }
132
            
133
        }else{//密码不一致
134
            [self.label showWarnMsg:CoreLockVerifyErrorPwdTitle];
135
        }
136
        
137
        return res;
138
    };
139
    
140
    /*
141
     *  修改
142
     */
143
    
144
    /** 开始 */
145
    self.lockView.modifyPwdBlock =^(){
146
        
147
        [self.label showNormalMsg:self.modifyCurrentTitle];
148
    };
149
    
150
    
151
}
152
153
154
/*
155
 *  数据传输
156
 */
157
-(void)dataTransfer{
158
    
159
    [self.label showNormalMsg:self.msg];
160
    
161
    //传递类型
162
    self.lockView.type = self.type;
163
}
164
165
/*
166
 *  控制器准备
167
 */
168
-(void)vcPrepare{
169
    
170
    //设置背景色
171
    self.view.backgroundColor = CoreLockViewBgColor;
172
    
173
    //初始情况隐藏
174
    self.navigationItem.rightBarButtonItem = nil;
175
    
176
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
177
    
178
    if (self.type != CoreLockTypeSetPwd) {
179
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
180
    }
181
    
182
    if(_isDirectModify){
183
        return;
184
    }
185
    
186
}
187
188
-(void)dismiss{
189
    [self dismiss:0];
190
}
191
192
#pragma mark - create and init
193
194
/*
195
 *  展示设置密码控制器
196
 */
197
+(instancetype)showSettingLockVCInVC:(UIViewController *)vc successBlock:(void(^)(CoreLockViewController *lockVC,NSString *pwd))successBlock{
198
    
199
    CoreLockViewController *lockVC = [self lockVC:vc Type:CoreLockTypeSetPwd];
200
    
201
//    lockVC.title = @"设置密码";
202
    
203
    //设置类型
204
    lockVC.type = CoreLockTypeSetPwd;
205
    lockVC.lockView.type = CoreLockTypeSetPwd;
206
    lockVC.msg = CoreLockPWDTitleFirst;
207
    [lockVC.label showNormalMsg:CoreLockPWDTitleFirst];
208
    
209
    //保存block
210
    lockVC.successBlock = successBlock;
211
    
212
    return lockVC;
213
}
214
215
216
217
218
/*
219
 *  展示验证密码输入框
220
 */
221
+(instancetype)showVerifyLockVCInVC:(UIViewController *)vc forgetPwdBlock:(void(^)())forgetPwdBlock successBlock:(void(^)(CoreLockViewController *lockVC, NSString *pwd))successBlock{
222
    
223
    
224
    CoreLockViewController *lockVC = [self lockVC:vc Type:CoreLockTypeVeryfiPwd];
225
    
226
//    lockVC.title = @"手势解锁";
227
    
228
    //设置类型
229
    lockVC.type = CoreLockTypeVeryfiPwd;
230
    lockVC.lockView.type = CoreLockTypeVeryfiPwd;
231
    lockVC.msg = CoreLockVerifyNormalTitle;
232
    [lockVC.label showNormalMsg:CoreLockVerifyNormalTitle];//请滑动输入密码
233
    
234
    //保存block
235
    lockVC.successBlock = successBlock;
236
    lockVC.forgetPwdBlock = forgetPwdBlock;
237
    
238
    return lockVC;
239
}
240
241
242
243
244
/*
245
 *  展示修改密码输入框
246
 */
247
+(instancetype)showModifyLockVCInVC:(UIViewController *)vc successBlock:(void(^)(CoreLockViewController *lockVC, NSString *pwd))successBlock{
248
    
249
    CoreLockViewController *lockVC = [self lockVC:vc Type:CoreLockTypeModifyPwd];
250
//    lockVC.title = @"修改密码";
251
    
252
    //设置类型
253
    lockVC.type = CoreLockTypeModifyPwd;
254
    lockVC.lockView.type = CoreLockTypeModifyPwd;
255
    lockVC.msg = CoreLockModifyNormalTitle;
256
    [lockVC.label showNormalMsg:CoreLockModifyNormalTitle];//请输入旧密码
257
    
258
    //记录
259
    lockVC.successBlock = successBlock;
260
    
261
    return lockVC;
262
}
263
264
+(instancetype)lockVC:(UIViewController *)vc Type:(CoreLockType)type{
265
    
266
    CoreLockViewController *lockVC = [[CoreLockViewController alloc] init];
267
    lockVC.vc = vc;
268
    
269
    //手势密码
270
    CLLockView * lockV = [[CLLockView alloc] initWithFrame:CGRectMake((kScreenW-lockViewWidth)/2, 150, lockViewWidth, lockViewWidth)];
271
    lockV.backgroundColor = [UIColor whiteColor];
272
    lockVC.lockView = lockV;
273
    [lockVC.view addSubview:lockVC.lockView];
274
    
275
    //提示信息
276
    CLLockLabel * lockL = [[CLLockLabel alloc] initWithFrame:CGRectMake(0, 100, kScreenW, 40)];
277
    lockL.textAlignment = NSTextAlignmentCenter;
278
    lockVC.label = lockL;
279
    [lockVC.view addSubview:lockVC.label];
280
    
281
    //导航信息封装
282
    UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:lockVC];
283
    [vc presentViewController:navVC animated:YES completion:nil];
284
    
285
    lockVC.navigationItem.leftBarButtonItem = lockVC.closeItem;
286
    
287
    return lockVC;
288
}
289
290
291
#pragma mark - fun action
292
-(void)setType:(CoreLockType)type{
293
    
294
    _type = type;
295
    
296
    //根据type自动调整label文字
297
    [self labelWithType];
298
}
299
300
/*
301
 *  根据type自动调整label文字
302
 */
303
-(void)labelWithType{
304
    
305
    if(CoreLockTypeSetPwd == _type){//设置密码
306
        
307
        self.msg = CoreLockPWDTitleFirst;
308
        
309
    }else if (CoreLockTypeVeryfiPwd == _type){//验证密码
310
        
311
        self.msg = CoreLockVerifyNormalTitle;
312
        
313
    }else if (CoreLockTypeModifyPwd == _type){//修改密码
314
        
315
        self.msg = CoreLockModifyNormalTitle;
316
    }
317
}
318
319
-(UIBarButtonItem *)closeItem{
320
    if(_closeItem == nil){
321
        //添加左按钮
322
        _closeItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:self action:@selector(closeAction)];
323
        NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
324
        [_closeItem setTitleTextAttributes:attrsDictionary forState:UIControlStateNormal];
325
    }
326
    return _closeItem;
327
}
328
329
-(void)closeAction{
330
    [self dismiss];
331
}
332
/*
333
 *  消失
334
 */
335
-(void)dismiss:(NSTimeInterval)interval{
336
    
337
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(interval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
338
        [self dismissViewControllerAnimated:YES completion:nil];
339
    });
340
}
341
342
/*
343
 *  重置
344
 */
345
-(UIBarButtonItem *)resetItem{
346
347
    if(_resetItem == nil){
348
        //添加右按钮
349
        _resetItem= [[UIBarButtonItem alloc] initWithTitle:@"重设" style:UIBarButtonItemStylePlain target:self action:@selector(setPwdReset)];
350
        NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
351
        [_resetItem setTitleTextAttributes:attrsDictionary forState:UIControlStateNormal];
352
    }
353
354
    return _resetItem;
355
}
356
357
/*
358
 *  密码重设
359
 */
360
-(void)setPwdReset{
361
362
    [self.label showNormalMsg:CoreLockPWDTitleFirst];
363
364
    //隐藏
365
    self.navigationItem.rightBarButtonItem = nil;
366
367
    //通知视图重设
368
    [self.lockView resetPwd];
369
}
370
371
-(UIBarButtonItem *)updateItem{
372
    if(_updateItem == nil){
373
        //添加右按钮
374
        _updateItem = [[UIBarButtonItem alloc] initWithTitle:@"修改密码" style:UIBarButtonItemStylePlain target:self action:@selector(setPwdUpdate)];
375
        NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
376
        [_updateItem setTitleTextAttributes:attrsDictionary forState:UIControlStateNormal];
377
    }
378
    return _updateItem;
379
}
380
381
-(void)setPwdUpdate{
382
    CoreLockViewController * lockVC = [[CoreLockViewController alloc] init];
383
384
    CLLockView * lockV = [[CLLockView alloc] initWithFrame:CGRectMake((kScreenW-lockViewWidth)/2, 150, lockViewWidth, lockViewWidth)];
385
    lockV.backgroundColor = [UIColor clearColor];
386
    lockVC.lockView = lockV;
387
    [lockVC.view addSubview:lockVC.lockView];
388
389
    CLLockLabel * lockL = [[CLLockLabel alloc] initWithFrame:CGRectMake(0, 100, kScreenW, 40)];
390
    lockL.textAlignment = NSTextAlignmentCenter;
391
    lockVC.label = lockL;
392
    [lockVC.view addSubview:lockVC.label];
393
394
    lockVC.title = @"修改密码";
395
    lockVC.isDirectModify = YES;
396
397
    //设置类型
398
    lockVC.type = CoreLockTypeModifyPwd;
399
    lockVC.lockView.type = CoreLockTypeModifyPwd;
400
    lockVC.msg = CoreLockModifyNormalTitle;
401
    [lockVC.label showNormalMsg:CoreLockModifyNormalTitle];
402
403
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
404
    NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
405
    [item setTitleTextAttributes:attrsDictionary forState:UIControlStateNormal];
406
    lockVC.navigationItem.leftBarButtonItem = item;
407
408
    [self.navigationController pushViewController:lockVC animated:YES];
409
410
    //记录
411
    __weak UIViewController * viewControll=self;
412
    lockVC.successBlock = ^(CoreLockViewController * lockVC, NSString * pwd) {
413
        [viewControll.navigationController popViewControllerAnimated:YES];
414
    };
415
}
416
-(void)backAction{
417
    [self.navigationController popViewControllerAnimated:YES];
418
}
419
420
- (void)didReceiveMemoryWarning {
421
    [super didReceiveMemoryWarning];
422
    // Dispose of any resources that can be recreated.
423
}
424
425
426
@end

+ 11 - 6
WadeMobileFunc/WadeMobileFunc/IpuAuthentication.h

@ -8,7 +8,6 @@
8 8
9 9
#import <WadeMobile/WadeMobile.h>
10 10
11
NS_ASSUME_NONNULL_BEGIN
12 11
13 12
@interface IpuAuthentication : WDPlugin
14 13
@ -35,22 +34,28 @@ NS_ASSUME_NONNULL_BEGIN
35 34
36 35
 @param params <#params description#>
37 36
 */
38
- (void)setGestureAuthentication:(NSArray *)params;
37
- (void)setGestureLock:(NSArray *)params;
39 38
40 39
/**
41 40
 手势解锁
42 41
43 42
 @param params <#params description#>
44 43
 */
45
- (void)gestureAuthentication:(NSArray *)params;
44
- (void)validateGestureLock:(NSArray *)params;
46 45
47 46
/**
48
 删除手势密码
47
 验证手势密码
48
49
 @param params <#params description#>
50
 */
51
- (void)updateGestureLock:(NSArray *)params;
49 52
53
/**
54
 删除手势密码
55
 
50 56
 @param params <#params description#>
51 57
 */
52
- (void)deleteGestureAuthentication:(NSArray *)params;
58
- (void)delGestureLock:(NSArray *)params;
53 59
54 60
@end
55 61
56
NS_ASSUME_NONNULL_END

+ 136 - 44
WadeMobileFunc/WadeMobileFunc/IpuAuthentication.m

@ -10,6 +10,8 @@
10 10
11 11
#import<LocalAuthentication/LocalAuthentication.h>
12 12
#import<WadeMobileFunc/WDFMobileStorage.h>
13
#import <WadeMobileFunc/CoreLockViewController.h>
14
#import <WadeMobileFunc/CoreLockConst.h>
13 15
14 16
@implementation IpuAuthentication
15 17
@ -74,69 +76,159 @@
74 76
}
75 77
76 78
#pragma mark - GestureAuthentication
77
78 79
/**
79 80
 设置手势锁
80
 
81
 @param params <#params description#>
82 81
 */
83
- (void)setGestureAuthentication:(NSArray *)params{
84
    NSArray *param = [[NSArray alloc] initWithObjects:@"gesture-lock-login",[NSNull null],@"false", nil];
85
    [WDPluginManager execute:wademobile action:@"openPage" arrayParam:param callback:@"openPage1"];
82
- (void)setGestureLock:(NSArray *)params{
83
    BOOL hasPwd = [self hasGesturePassword];
84
    hasPwd = NO;
85
    if(hasPwd){
86
        [self callback:@"已经设置过密码了,你可以验证或者修改密码"];
87
    }else{
88
        [CoreLockViewController showSettingLockVCInVC:[self getViewController] successBlock:^(CoreLockViewController *lockVC, NSString *pwd) {
89
            [lockVC dismiss:1.0f];
90
        }];
91
    }
86 92
}
87 93
88 94
/**
89 95
 手势解锁
90
 
91
 @param params <#params description#>
92 96
 */
93
- (void)gestureAuthentication:(NSArray *)params{
94
    //如果存在手势密码则显示手势锁界面
95
    NSString *gesturepassword = [self getCurrentUserGestureValue];
96
    if(gesturepassword && gesturepassword.length>0){
97
        NSArray *params = [[NSArray alloc] initWithObjects:@"gesture-lock-login",[NSNull null],@"false", nil];
98
        [WDPluginManager execute:wademobile action:@"openPage" arrayParam:params callback:@"openPage1"];
97
- (void)validateGestureLock:(NSArray *)params{
98
    BOOL hasPwd = [self hasGesturePassword];
99
    if(!hasPwd){
100
        [self callback:@"你还没有设置密码,请先设置密码"];
101
    }else {
102
        [CoreLockViewController showVerifyLockVCInVC:[self getViewController] forgetPwdBlock:^{
103
            NSLog(@"密码错误");
104
        } successBlock:^(CoreLockViewController *lockVC, NSString *pwd) {
105
            NSLog(@"密码正确");
106
            [lockVC dismiss:1.0f];
107
        }];
99 108
    }
100 109
}
101 110
102
/*
103
 获取手势密码
111
/**
112
 修改手势密码
104 113
 */
105
-(NSString *)getCurrentUserGestureValue{
106
    WDFMobileStorage *storage = [WDPluginManager getPlugin:@"WDFMobileStorage" withWademobile:wademobile];
107
    NSString *currentUserAcount = [storage getOfflineCache:@"currentUserAccount" defValue:nil];
108
    if(currentUserAcount && currentUserAcount.length>0){
109
        NSString *userAccountListString = [storage getOfflineCache:@"userAccountList" defValue:nil];
110
        NSData *data = [userAccountListString dataUsingEncoding:NSUTF8StringEncoding];
111
        NSError *err;
112
        NSArray *arrDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&err];
113
        if(!err){
114
            if(arrDic && arrDic.count>0){
115
                NSDictionary *itemDic;
116
                NSString *userAcount;
117
                for(int i=0;i<arrDic.count;i++){
118
                    itemDic = arrDic[i];
119
                    userAcount = [itemDic objectForKey:@"userAccount"];
120
                    if([userAcount isEqualToString:currentUserAcount]){
121
                        return [itemDic objectForKey:@"gesturePasswd"];
122
                    }
123
                }
124
            }
125
        }else{
126
            NSLog(@"json解析失败!!!!!");
127
        }
114
- (void)updateGestureLock:(NSArray *)params{
115
    BOOL hasPwd = [self hasGesturePassword];
116
    if(!hasPwd){
117
        [self callback:@"你还没有设置密码,请先设置密码"];
118
    }else {
119
        [CoreLockViewController showModifyLockVCInVC:[self getViewController] successBlock:^(CoreLockViewController *lockVC, NSString *pwd) {
120
            [lockVC dismiss:.5f];
121
        }];
128 122
    }
129
    return nil;
130 123
}
131
132 124
/**
133 125
 删除手势密码
134
 
135
 @param params <#params description#>
136 126
 */
137
- (void)deleteGestureAuthentication:(NSArray *)params{
127
- (void)delGestureLock:(NSArray *)params{
128
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
129
    [defaults setObject:nil forKey:CoreLockPWDKey];
130
}
131
132
/*
133
 判断是否设置过手势密码
134
 */
135
-(BOOL)hasGesturePassword{
136
    //获取preference
137
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
138
    //读取
139
    NSString * str = (NSString *)[defaults objectForKey:CoreLockPWDKey];
140
    if (str) {
141
        return YES;
142
    }
143
    return NO;
144
}
145
/*
146
 保存手势密码
147
 */
148
-(void)setCoreLockPassword:(NSString *)str{
149
    //获取preference
150
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
138 151
    
152
    //保存
153
    [defaults setObject:str forKey:CoreLockPWDKey];
154
    
155
    //立即同步
156
    [defaults synchronize];
139 157
}
158
/*
159
 获取保存在本地的手势密码
160
 */
161
-(NSString *)fetchCoreLockPassword{
162
    //获取preference
163
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
164
    
165
    //读取
166
    NSString * str = (NSString *)[defaults objectForKey:CoreLockPWDKey];
167
    
168
    return str;
169
}
170
171
///**
172
// 设置手势锁
173
//
174
// @param params <#params description#>
175
// */
176
//- (void)setGestureLock:(NSArray *)params{
177
//    NSArray *param = [[NSArray alloc] initWithObjects:@"gesture-lock-login",[NSNull null],@"false", nil];
178
//    [WDPluginManager execute:wademobile action:@"openPage" arrayParam:param callback:@"openPage1"];
179
//}
180
//
181
///**
182
// 手势解锁
183
//
184
// @param params <#params description#>
185
// */
186
//- (void)validateGestureLock:(NSArray *)params{
187
//    //如果存在手势密码则显示手势锁界面
188
//    NSString *gesturepassword = [self getCurrentUserGestureValue];
189
//    if(gesturepassword && gesturepassword.length>0){
190
//        NSArray *params = [[NSArray alloc] initWithObjects:@"gesture-lock-login",[NSNull null],@"false", nil];
191
//        [WDPluginManager execute:wademobile action:@"openPage" arrayParam:params callback:@"openPage1"];
192
//    }
193
//}
194
//
195
///**
196
// 删除手势密码
197
//
198
// @param params <#params description#>
199
// */
200
//- (void)delGestureLock:(NSArray *)params{
201
//
202
//}
203
///*
204
// 获取手势密码
205
// */
206
//-(NSString *)getCurrentUserGestureValue{
207
//    WDFMobileStorage *storage = [WDPluginManager getPlugin:@"WDFMobileStorage" withWademobile:wademobile];
208
//    NSString *currentUserAcount = [storage getOfflineCache:@"currentUserAccount" defValue:nil];
209
//    if(currentUserAcount && currentUserAcount.length>0){
210
//        NSString *userAccountListString = [storage getOfflineCache:@"userAccountList" defValue:nil];
211
//        NSData *data = [userAccountListString dataUsingEncoding:NSUTF8StringEncoding];
212
//        NSError *err;
213
//        NSArray *arrDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&err];
214
//        if(!err){
215
//            if(arrDic && arrDic.count>0){
216
//                NSDictionary *itemDic;
217
//                NSString *userAcount;
218
//                for(int i=0;i<arrDic.count;i++){
219
//                    itemDic = arrDic[i];
220
//                    userAcount = [itemDic objectForKey:@"userAccount"];
221
//                    if([userAcount isEqualToString:currentUserAcount]){
222
//                        return [itemDic objectForKey:@"gesturePasswd"];
223
//                    }
224
//                }
225
//            }
226
//        }else{
227
//            NSLog(@"json解析失败!!!!!");
228
//        }
229
//    }
230
//    return nil;
231
//}
140 232
141 233
142 234
@end