diff --git a/ManagerDemo.xcodeproj/project.pbxproj b/ManagerDemo.xcodeproj/project.pbxproj index d97f195..45d9985 100644 --- a/ManagerDemo.xcodeproj/project.pbxproj +++ b/ManagerDemo.xcodeproj/project.pbxproj @@ -199,6 +199,11 @@ A9C0540519ADBCB2002331A5 /* FundProductInfoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C0540319ADBCB2002331A5 /* FundProductInfoViewController.m */; }; A9C0540619ADBCB2002331A5 /* FundProductInfoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9C0540419ADBCB2002331A5 /* FundProductInfoViewController.xib */; }; A9C2E4E519B6A0C900C659B3 /* icon_email@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = A9C2E4E419B6A0C900C659B3 /* icon_email@2x.png */; }; + A9C353A81A0C711000EE8247 /* GesturePasswordButton.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C3539E1A0C711000EE8247 /* GesturePasswordButton.m */; }; + A9C353A91A0C711000EE8247 /* GesturePasswordController.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C353A01A0C711000EE8247 /* GesturePasswordController.m */; }; + A9C353AA1A0C711000EE8247 /* GesturePasswordView.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C353A21A0C711000EE8247 /* GesturePasswordView.m */; }; + A9C353AB1A0C711000EE8247 /* KeychainItemWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C353A51A0C711000EE8247 /* KeychainItemWrapper.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + A9C353AC1A0C711000EE8247 /* TentacleView.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C353A71A0C711000EE8247 /* TentacleView.m */; }; A9C69442199BB7B100B2CECE /* icon_person_take_image@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = A9C69441199BB7B100B2CECE /* icon_person_take_image@2x.png */; }; A9C69446199BBEB200B2CECE /* MyTotalProfitCellView.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C69445199BBEB200B2CECE /* MyTotalProfitCellView.m */; }; A9C69448199BC1F500B2CECE /* gray_select_arrow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = A9C69447199BC1F500B2CECE /* gray_select_arrow@2x.png */; }; @@ -525,6 +530,16 @@ A9C0540319ADBCB2002331A5 /* FundProductInfoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FundProductInfoViewController.m; sourceTree = ""; }; A9C0540419ADBCB2002331A5 /* FundProductInfoViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FundProductInfoViewController.xib; sourceTree = ""; }; A9C2E4E419B6A0C900C659B3 /* icon_email@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_email@2x.png"; sourceTree = ""; }; + A9C3539D1A0C711000EE8247 /* GesturePasswordButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GesturePasswordButton.h; sourceTree = ""; }; + A9C3539E1A0C711000EE8247 /* GesturePasswordButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GesturePasswordButton.m; sourceTree = ""; }; + A9C3539F1A0C711000EE8247 /* GesturePasswordController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GesturePasswordController.h; sourceTree = ""; }; + A9C353A01A0C711000EE8247 /* GesturePasswordController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GesturePasswordController.m; sourceTree = ""; }; + A9C353A11A0C711000EE8247 /* GesturePasswordView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GesturePasswordView.h; sourceTree = ""; }; + A9C353A21A0C711000EE8247 /* GesturePasswordView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GesturePasswordView.m; sourceTree = ""; }; + A9C353A41A0C711000EE8247 /* KeychainItemWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeychainItemWrapper.h; sourceTree = ""; }; + A9C353A51A0C711000EE8247 /* KeychainItemWrapper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KeychainItemWrapper.m; sourceTree = ""; }; + A9C353A61A0C711000EE8247 /* TentacleView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TentacleView.h; sourceTree = ""; }; + A9C353A71A0C711000EE8247 /* TentacleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TentacleView.m; sourceTree = ""; }; A9C69441199BB7B100B2CECE /* icon_person_take_image@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_person_take_image@2x.png"; sourceTree = ""; }; A9C69444199BBEB200B2CECE /* MyTotalProfitCellView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyTotalProfitCellView.h; sourceTree = ""; }; A9C69445199BBEB200B2CECE /* MyTotalProfitCellView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyTotalProfitCellView.m; sourceTree = ""; }; @@ -890,6 +905,7 @@ A9AF6C4A19949B510076C0EE /* Common */ = { isa = PBXGroup; children = ( + A9C3539C1A0C711000EE8247 /* GesturePassword */, A9A6AD3619CB30E400626B48 /* UPPay */, A9354F5819B870B900FDCB52 /* BaseView */, A986268419B40AAC00FF9E2C /* SVWebViewController */, @@ -1048,6 +1064,31 @@ path = MainView; sourceTree = ""; }; + A9C3539C1A0C711000EE8247 /* GesturePassword */ = { + isa = PBXGroup; + children = ( + A9C3539D1A0C711000EE8247 /* GesturePasswordButton.h */, + A9C3539E1A0C711000EE8247 /* GesturePasswordButton.m */, + A9C3539F1A0C711000EE8247 /* GesturePasswordController.h */, + A9C353A01A0C711000EE8247 /* GesturePasswordController.m */, + A9C353A11A0C711000EE8247 /* GesturePasswordView.h */, + A9C353A21A0C711000EE8247 /* GesturePasswordView.m */, + A9C353A31A0C711000EE8247 /* KeychainItemWrapper */, + A9C353A61A0C711000EE8247 /* TentacleView.h */, + A9C353A71A0C711000EE8247 /* TentacleView.m */, + ); + path = GesturePassword; + sourceTree = ""; + }; + A9C353A31A0C711000EE8247 /* KeychainItemWrapper */ = { + isa = PBXGroup; + children = ( + A9C353A41A0C711000EE8247 /* KeychainItemWrapper.h */, + A9C353A51A0C711000EE8247 /* KeychainItemWrapper.m */, + ); + path = KeychainItemWrapper; + sourceTree = ""; + }; A9C69443199BBE9500B2CECE /* MyView */ = { isa = PBXGroup; children = ( @@ -1438,8 +1479,11 @@ A99EBEC419CBB47C005E1AA0 /* HelpCenterViewController.m in Sources */, A9AF6C921994C5700076C0EE /* MJRefreshFooterView.m in Sources */, A9202B8719C95B97009932C2 /* ProFitCaculateViewController.m in Sources */, + A9C353A81A0C711000EE8247 /* GesturePasswordButton.m in Sources */, A93F87CA1999E62000875287 /* AdjustableUILable.m in Sources */, A93F8803199A077F00875287 /* LoanListCell.m in Sources */, + A9C353A91A0C711000EE8247 /* GesturePasswordController.m in Sources */, + A9C353AC1A0C711000EE8247 /* TentacleView.m in Sources */, A9AA326019970335000BE4FB /* HomeAdView.m in Sources */, A988A900199A751500EB10AA /* FundListCell.m in Sources */, A9AF6C3D199486CA0076C0EE /* ProductListViewController.m in Sources */, @@ -1458,6 +1502,7 @@ A9623E2F19CBEB1A004F7D9D /* NSDictionary+ChangeNull.m in Sources */, A9354F5C19B870C700FDCB52 /* BaseListViewController.m in Sources */, A95CEA4019B766F400D4605F /* MessageDetailViewController.m in Sources */, + A9C353AA1A0C711000EE8247 /* GesturePasswordView.m in Sources */, A96F2A7F199D01C000608237 /* NSString+FontAwesome.m in Sources */, A9EAA035199857F5001A872A /* HomeMainView.m in Sources */, A919055619B02741002575DF /* AccountInfoViewController.m in Sources */, @@ -1510,6 +1555,7 @@ A99FDB0A19CAC16E00D2B3D3 /* SetPassWordViewController.m in Sources */, A9AF6C2E199483520076C0EE /* MainViewController.m in Sources */, A9EE5EE719C20CDA004E7A2C /* WYDAmountTableViewCell.m in Sources */, + A9C353AB1A0C711000EE8247 /* KeychainItemWrapper.m in Sources */, A9AF6C42199498C40076C0EE /* MyViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/ManagerDemo.xcworkspace/xcuserdata/xmfish.xcuserdatad/UserInterfaceState.xcuserstate b/ManagerDemo.xcworkspace/xcuserdata/xmfish.xcuserdatad/UserInterfaceState.xcuserstate index 04e48f2..ab43946 100644 Binary files a/ManagerDemo.xcworkspace/xcuserdata/xmfish.xcuserdatad/UserInterfaceState.xcuserstate and b/ManagerDemo.xcworkspace/xcuserdata/xmfish.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ManagerDemo/AppDelegate.m b/ManagerDemo/AppDelegate.m index e9bc641..9b5092b 100644 --- a/ManagerDemo/AppDelegate.m +++ b/ManagerDemo/AppDelegate.m @@ -35,11 +35,15 @@ - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + if ([ManagerUser shareInstance].isLogin && [ManagerUser shareInstance].isGesturePsw) { + [ManagerUtil presentGesturePsw]; + } } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } - (void)applicationWillTerminate:(UIApplication *)application diff --git a/ManagerDemo/Common/GesturePassword/.DS_Store b/ManagerDemo/Common/GesturePassword/.DS_Store new file mode 100644 index 0000000..769ac10 Binary files /dev/null and b/ManagerDemo/Common/GesturePassword/.DS_Store differ diff --git a/ManagerDemo/Common/GesturePassword/GesturePasswordButton.h b/ManagerDemo/Common/GesturePassword/GesturePasswordButton.h new file mode 100755 index 0000000..3abc776 --- /dev/null +++ b/ManagerDemo/Common/GesturePassword/GesturePasswordButton.h @@ -0,0 +1,17 @@ +// +// GesturePasswordButton.h +// GesturePassword +// +// Created by hb on 14-8-23. +// Copyright (c) 2014年 黑と白の印记. All rights reserved. +// + +#import + +@interface GesturePasswordButton : UIView + +@property (nonatomic,assign) BOOL selected; + +@property (nonatomic,assign) BOOL success; + +@end diff --git a/ManagerDemo/Common/GesturePassword/GesturePasswordButton.m b/ManagerDemo/Common/GesturePassword/GesturePasswordButton.m new file mode 100755 index 0000000..90e8b10 --- /dev/null +++ b/ManagerDemo/Common/GesturePassword/GesturePasswordButton.m @@ -0,0 +1,72 @@ +// +// GesturePasswordButton.m +// GesturePassword +// +// Created by hb on 14-8-23. +// Copyright (c) 2014年 黑と白の印记. All rights reserved. +// + +#import "GesturePasswordButton.h" + +#define bounds self.bounds + +@implementation GesturePasswordButton +@synthesize selected; +@synthesize success; + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + // Initialization code + success=YES; + [self setBackgroundColor:[UIColor clearColor]]; + } + return self; +} + + +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawRect:(CGRect)rect +{ + // Drawing code + CGContextRef context = UIGraphicsGetCurrentContext(); + + if (selected) { + if (success) { + CGContextSetRGBStrokeColor(context, 2/255.f, 174/255.f, 240/255.f,1);//线条颜色 + CGContextSetRGBFillColor(context,2/255.f, 174/255.f, 240/255.f,1); + } + else { + CGContextSetRGBStrokeColor(context, 208/255.f, 36/255.f, 36/255.f,1);//线条颜色 + CGContextSetRGBFillColor(context,208/255.f, 36/255.f, 36/255.f,1); + } + CGRect frame = CGRectMake(bounds.size.width/2-bounds.size.width/8+1, bounds.size.height/2-bounds.size.height/8, bounds.size.width/4, bounds.size.height/4); + + CGContextAddEllipseInRect(context,frame); + CGContextFillPath(context); + } + else{ + CGContextSetRGBStrokeColor(context, 1,1,1,1);//线条颜色 + } + + CGContextSetLineWidth(context,2); + CGRect frame = CGRectMake(2, 2, bounds.size.width-3, bounds.size.height-3); + CGContextAddEllipseInRect(context,frame); + CGContextStrokePath(context); + if (success) { + CGContextSetRGBFillColor(context,30/255.f, 175/255.f, 235/255.f,0.3); + } + else { + CGContextSetRGBFillColor(context,208/255.f, 36/255.f, 36/255.f,0.3); + } + CGContextAddEllipseInRect(context,frame); + if (selected) { + CGContextFillPath(context); + } + +} + + +@end diff --git a/ManagerDemo/Common/GesturePassword/GesturePasswordController.h b/ManagerDemo/Common/GesturePassword/GesturePasswordController.h new file mode 100755 index 0000000..23da99f --- /dev/null +++ b/ManagerDemo/Common/GesturePassword/GesturePasswordController.h @@ -0,0 +1,21 @@ +// +// GesturePasswordController.h +// GesturePassword +// +// Created by hb on 14-8-23. +// Copyright (c) 2014年 黑と白の印记. All rights reserved. +// + + + +#import +#import "TentacleView.h" +#import "GesturePasswordView.h" + +@interface GesturePasswordController : UIViewController + +- (void)clear; + +- (BOOL)exist; + +@end diff --git a/ManagerDemo/Common/GesturePassword/GesturePasswordController.m b/ManagerDemo/Common/GesturePassword/GesturePasswordController.m new file mode 100755 index 0000000..a21d3b2 --- /dev/null +++ b/ManagerDemo/Common/GesturePassword/GesturePasswordController.m @@ -0,0 +1,238 @@ +// +// GesturePasswordController.m +// GesturePassword +// +// Created by hb on 14-8-23. +// Copyright (c) 2014年 黑と白の印记. All rights reserved. +// + +#import +#import + +#import "GesturePasswordController.h" + + +#import "KeychainItemWrapper/KeychainItemWrapper.h" + +@interface GesturePasswordController () + +@property (nonatomic,strong) GesturePasswordView * gesturePasswordView; + +@end + +@implementation GesturePasswordController { + NSString * previousString; + NSString * password; + UIView* showView; + BOOL _isModify; +} + +@synthesize gesturePasswordView; + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + gesturePasswordView = nil; + showView = nil; + } + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + // Do any additional setup after loading the view. + + _isModify = NO; + previousString = [NSString string]; + self.navigationItem.title = @"设置手势密码"; + password = [ManagerUser shareInstance].gesturePsw; + + if ([password isEqualToString:@""] || ![ManagerUser shareInstance].isGesturePsw) { + + [self reset]; + self.navigationItem.title = @"设置手势密码"; + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(cancel)]; + } + else { + [self verify]; + self.navigationItem.title = @"验证手势密码"; + } + +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +-(void)cancel +{ + if ([[ManagerUser shareInstance].gesturePsw isEqualToString:@""]) { + [ManagerUser shareInstance].isGesturePsw = NO; + } + [self dismissViewControllerAnimated:YES completion:^{ + + }]; +} +#pragma mark - 验证手势密码 +- (void)verify{ + if(gesturePasswordView.superview) + { + [gesturePasswordView removeFromSuperview]; + gesturePasswordView = nil; + } + gesturePasswordView = [[GesturePasswordView alloc]initWithFrame:[UIScreen mainScreen].bounds]; + [gesturePasswordView.tentacleView setRerificationDelegate:self]; + [gesturePasswordView.tentacleView setStyle:1]; + [gesturePasswordView setGesturePasswordDelegate:self]; + [self.view addSubview:gesturePasswordView]; +} + +#pragma mark - 上面的表示图案 +-(void)drawShowView{ + showView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; + showView.backgroundColor = [UIColor clearColor]; + for(int i = 0; i < 9; i++){ + UIView* view = [[UIView alloc] initWithFrame:CGRectMake(i%3*15, i/3*15, 10, 10)]; + view.backgroundColor = [UIColor blackColor]; + view.layer.cornerRadius = 5.0; + view.layer.masksToBounds = YES; + view.tag = i+1; + [showView addSubview:view]; + } + showView.center = CGPointMake(165, 120); + [self.view addSubview:showView]; +} +-(void)drawShowViewWithResult:(NSString*)resultStr{ + for(int i = 0; i < resultStr.length; i++){ + NSInteger tag = [resultStr characterAtIndex:i]-48+1; + [showView viewWithTag:tag].backgroundColor = [UIColor orangeColor]; + } +} +#pragma mark - 重置手势密码 +- (void)reset{ + + [ManagerUser shareInstance].gesturePsw = @""; + if(gesturePasswordView.superview) + { + [gesturePasswordView removeFromSuperview]; + gesturePasswordView = nil; + } + gesturePasswordView = [[GesturePasswordView alloc]initWithFrame:[UIScreen mainScreen].bounds]; + [gesturePasswordView.tentacleView setResetDelegate:self]; + [gesturePasswordView.tentacleView setStyle:2]; +// [gesturePasswordView.imgView setHidden:YES]; + [gesturePasswordView.forgetButton setHidden:YES]; + [gesturePasswordView.changeButton setHidden:YES]; + [gesturePasswordView.state setTextColor:[UIColor colorWithRed:2/255.f green:174/255.f blue:240/255.f alpha:1]]; + [gesturePasswordView.state setText:@"绘制解锁图案"]; + [self.view addSubview:gesturePasswordView]; + [self drawShowView]; +} + +#pragma mark - 判断是否已存在手势密码 +- (BOOL)exist{ + password = [ManagerUser shareInstance].gesturePsw; + if ([password isEqualToString:@""])return NO; + return YES; +} + +#pragma mark - 清空记录 +- (void)clear{ + [ManagerUser shareInstance].gesturePsw = @""; +} + +#pragma mark - 改变手势密码 +- (void)change{ + _isModify = YES; + [gesturePasswordView.state setTextColor:[UIColor colorWithRed:2/255.f green:174/255.f blue:240/255.f alpha:1]]; + [gesturePasswordView.state setText:@"先确认密码再修改"]; +} + +#pragma mark - 忘记手势密码 +- (void)forget{ + UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"忘记手势密码需要重新登录设置" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil]; + [alertView show]; + [ManagerUtil presentLoginView]; +// [self reset]; +} +#pragma mark UIAlertViewDelegate +-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex +{ + if (buttonIndex == 1) { + [ManagerUser shareInstance].isLogin = false; + [ManagerUser shareInstance].isGesturePsw = false; + [ManagerUser shareInstance].gesturePsw = @""; + [self dismissViewControllerAnimated:NO completion:^{ + [ManagerUtil presentLoginView]; + }]; + + } +} + +- (BOOL)verification:(NSString *)result{ + if ([result isEqualToString:password]) { + [gesturePasswordView.state setTextColor:[UIColor colorWithRed:2/255.f green:174/255.f blue:240/255.f alpha:1]]; + [gesturePasswordView.state setText:@"输入正确"]; + if (_isModify) { + [self reset]; + }else{ + [self dismissViewControllerAnimated:YES completion:^{ + }]; + } + + //[self presentViewController:(UIViewController) animated:YES completion:nil]; + return YES; + } + [gesturePasswordView.state setTextColor:[UIColor redColor]]; + [gesturePasswordView.state setText:@"手势密码错误"]; + return NO; +} + +- (BOOL)resetPassword:(NSString *)result{ + if ([previousString isEqualToString:@""]) { + previousString=result; + [gesturePasswordView.tentacleView enterArgin]; + [gesturePasswordView.state setTextColor:[UIColor colorWithRed:2/255.f green:174/255.f blue:240/255.f alpha:1]]; + [gesturePasswordView.state setText:@"请验证输入密码"]; + [self drawShowViewWithResult:result]; + return YES; + } + else { + if ([result isEqualToString:previousString]) { + [ManagerUser shareInstance].gesturePsw = result; + //[self presentViewController:(UIViewController) animated:YES completion:nil]; + [gesturePasswordView.state setTextColor:[UIColor colorWithRed:2/255.f green:174/255.f blue:240/255.f alpha:1]]; + [gesturePasswordView.state setText:@"已保存手势密码"]; + [self dismissViewControllerAnimated:YES completion:^{ + }]; + return YES; + } + else{ + previousString =@""; + [gesturePasswordView.state setTextColor:[UIColor redColor]]; + [gesturePasswordView.state setText:@"两次密码不一致,请重新输入"]; + return NO; + } + } +} + + + + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +{ + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@end diff --git a/ManagerDemo/Common/GesturePassword/GesturePasswordView.h b/ManagerDemo/Common/GesturePassword/GesturePasswordView.h new file mode 100755 index 0000000..0cc3aff --- /dev/null +++ b/ManagerDemo/Common/GesturePassword/GesturePasswordView.h @@ -0,0 +1,31 @@ +// +// GesturePasswordView.h +// GesturePassword +// +// Created by hb on 14-8-23. +// Copyright (c) 2014年 黑と白の印记. All rights reserved. +// + +@protocol GesturePasswordDelegate + +- (void)forget; +- (void)change; + +@end + +#import +#import "TentacleView.h" + +@interface GesturePasswordView : UIView + +@property (nonatomic,strong) TentacleView * tentacleView; + +@property (nonatomic,strong) UILabel * state; + +@property (nonatomic,assign) id gesturePasswordDelegate; + +@property (nonatomic,strong) UIImageView * imgView; +@property (nonatomic,strong) UIButton * forgetButton; +@property (nonatomic,strong) UIButton * changeButton; + +@end diff --git a/ManagerDemo/Common/GesturePassword/GesturePasswordView.m b/ManagerDemo/Common/GesturePassword/GesturePasswordView.m new file mode 100755 index 0000000..c395bef --- /dev/null +++ b/ManagerDemo/Common/GesturePassword/GesturePasswordView.m @@ -0,0 +1,122 @@ +// +// GesturePasswordView.m +// GesturePassword +// +// Created by hb on 14-8-23. +// Copyright (c) 2014年 黑と白の印记. All rights reserved. +// + +#import "GesturePasswordView.h" +#import "GesturePasswordButton.h" +#import "TentacleView.h" + +@implementation GesturePasswordView { + NSMutableArray * buttonArray; + + CGPoint lineStartPoint; + CGPoint lineEndPoint; + +} +@synthesize imgView; +@synthesize forgetButton; +@synthesize changeButton; + +@synthesize tentacleView; +@synthesize state; +@synthesize gesturePasswordDelegate; + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + // Initialization code + buttonArray = [[NSMutableArray alloc]initWithCapacity:0]; + + UIView * view = [[UIView alloc]initWithFrame:CGRectMake(frame.size.width/2-160, frame.size.height/2-100, 320, 320)]; + for (int i=0; i<9; i++) { + NSInteger row = i/3; + NSInteger col = i%3; + // Button Frame + + NSInteger distance = 320/3; + NSInteger size = distance/1.5; + NSInteger margin = size/4; + GesturePasswordButton * gesturePasswordButton = [[GesturePasswordButton alloc]initWithFrame:CGRectMake(col*distance+margin, row*distance, size, size)]; + [gesturePasswordButton setTag:i]; + [view addSubview:gesturePasswordButton]; + [buttonArray addObject:gesturePasswordButton]; + } + frame.origin.y=0; + [self addSubview:view]; + tentacleView = [[TentacleView alloc]initWithFrame:view.frame]; + [tentacleView setButtonArray:buttonArray]; + [tentacleView setTouchBeginDelegate:self]; + [self addSubview:tentacleView]; + + state = [[UILabel alloc]initWithFrame:CGRectMake(frame.size.width/2-140, frame.size.height/2-140, 280, 30)]; + [state setTextAlignment:NSTextAlignmentCenter]; + [state setFont:[UIFont systemFontOfSize:14.f]]; + [self addSubview:state]; + + +// imgView = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width/2-35, frame.size.width/2-80, 70, 70)]; +// [imgView setBackgroundColor:[UIColor whiteColor]]; +// [imgView.layer setCornerRadius:35]; +// [imgView.layer setBorderColor:[UIColor grayColor].CGColor]; +// [imgView.layer setBorderWidth:3]; +// [self addSubview:imgView]; + + forgetButton = [[UIButton alloc]initWithFrame:CGRectMake(frame.size.width/2-150, frame.size.height-35, 120, 30)]; + [forgetButton.titleLabel setFont:[UIFont systemFontOfSize:14]]; + [forgetButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [forgetButton setTitle:@"忘记手势密码" forState:UIControlStateNormal]; + [forgetButton addTarget:self action:@selector(forget) forControlEvents:UIControlEventTouchDown]; + [self addSubview:forgetButton]; + + changeButton = [[UIButton alloc]initWithFrame:CGRectMake(frame.size.width/2+30, frame.size.height-35, 120, 30)]; + [changeButton.titleLabel setFont:[UIFont systemFontOfSize:14]]; + [changeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [changeButton setTitle:@"修改手势密码" forState:UIControlStateNormal]; + [changeButton addTarget:self action:@selector(change) forControlEvents:UIControlEventTouchDown]; + [self addSubview:changeButton]; + } + + return self; +} + +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. + +- (void)drawRect:(CGRect)rect +{ + // Drawing code + CGContextRef context = UIGraphicsGetCurrentContext(); + + CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); + CGFloat colors[] = + { + 134 / 255.0, 157 / 255.0, 147 / 255.0, 1.00, + 3 / 255.0, 3 / 255.0, 37 / 255.0, 1.00, + }; + CGGradientRef gradient = CGGradientCreateWithColorComponents + (rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4)); + CGColorSpaceRelease(rgb); + CGContextDrawLinearGradient(context, gradient,CGPointMake + (0.0,0.0) ,CGPointMake(0.0,self.frame.size.height), + kCGGradientDrawsBeforeStartLocation); +} + +- (void)gestureTouchBegin { + [self.state setText:@""]; +} + +-(void)forget{ + [gesturePasswordDelegate forget]; +} + +-(void)change{ + [gesturePasswordDelegate change]; +} + + +@end diff --git a/ManagerDemo/Common/GesturePassword/KeychainItemWrapper/KeychainItemWrapper.h b/ManagerDemo/Common/GesturePassword/KeychainItemWrapper/KeychainItemWrapper.h new file mode 100755 index 0000000..2ec18cb --- /dev/null +++ b/ManagerDemo/Common/GesturePassword/KeychainItemWrapper/KeychainItemWrapper.h @@ -0,0 +1,74 @@ +/* + File: KeychainItemWrapper.h + Abstract: + Objective-C wrapper for accessing a single keychain item. + + Version: 1.2 + + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple + Inc. ("Apple") in consideration of your agreement to the following + terms, and your use, installation, modification or redistribution of + this Apple software constitutes acceptance of these terms. If you do + not agree with these terms, please do not use, install, modify or + redistribute this Apple software. + + In consideration of your agreement to abide by the following terms, and + subject to these terms, Apple grants you a personal, non-exclusive + license, under Apple's copyrights in this original Apple software (the + "Apple Software"), to use, reproduce, modify and redistribute the Apple + Software, with or without modifications, in source and/or binary forms; + provided that if you redistribute the Apple Software in its entirety and + without modifications, you must retain this notice and the following + text and disclaimers in all such redistributions of the Apple Software. + Neither the name, trademarks, service marks or logos of Apple Inc. may + be used to endorse or promote products derived from the Apple Software + without specific prior written permission from Apple. Except as + expressly stated in this notice, no other rights or licenses, express or + implied, are granted by Apple herein, including but not limited to any + patent rights that may be infringed by your derivative works or by other + works in which the Apple Software may be incorporated. + + The Apple Software is provided by Apple on an "AS IS" basis. APPLE + MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION + THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND + OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. + + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, + MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED + AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), + STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + Copyright (C) 2010 Apple Inc. All Rights Reserved. + +*/ + +#import + +/* + The KeychainItemWrapper class is an abstraction layer for the iPhone Keychain communication. It is merely a + simple wrapper to provide a distinct barrier between all the idiosyncracies involved with the Keychain + CF/NS container objects. +*/ +@interface KeychainItemWrapper : NSObject +{ + NSMutableDictionary *keychainItemData; // The actual keychain item data backing store. + NSMutableDictionary *genericPasswordQuery; // A placeholder for the generic keychain item query used to locate the item. +} + +@property (nonatomic, retain) NSMutableDictionary *keychainItemData; +@property (nonatomic, retain) NSMutableDictionary *genericPasswordQuery; + +// Designated initializer. +- (id)initWithIdentifier: (NSString *)identifier accessGroup:(NSString *) accessGroup; +- (void)setObject:(id)inObject forKey:(id)key; +- (id)objectForKey:(id)key; + +// Initializes and resets the default generic keychain item data. +- (void)resetKeychainItem; + +@end \ No newline at end of file diff --git a/ManagerDemo/Common/GesturePassword/KeychainItemWrapper/KeychainItemWrapper.m b/ManagerDemo/Common/GesturePassword/KeychainItemWrapper/KeychainItemWrapper.m new file mode 100755 index 0000000..cef5d56 --- /dev/null +++ b/ManagerDemo/Common/GesturePassword/KeychainItemWrapper/KeychainItemWrapper.m @@ -0,0 +1,313 @@ +/* + File: KeychainItemWrapper.m + Abstract: + Objective-C wrapper for accessing a single keychain item. + + Version: 1.2 + + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple + Inc. ("Apple") in consideration of your agreement to the following + terms, and your use, installation, modification or redistribution of + this Apple software constitutes acceptance of these terms. If you do + not agree with these terms, please do not use, install, modify or + redistribute this Apple software. + + In consideration of your agreement to abide by the following terms, and + subject to these terms, Apple grants you a personal, non-exclusive + license, under Apple's copyrights in this original Apple software (the + "Apple Software"), to use, reproduce, modify and redistribute the Apple + Software, with or without modifications, in source and/or binary forms; + provided that if you redistribute the Apple Software in its entirety and + without modifications, you must retain this notice and the following + text and disclaimers in all such redistributions of the Apple Software. + Neither the name, trademarks, service marks or logos of Apple Inc. may + be used to endorse or promote products derived from the Apple Software + without specific prior written permission from Apple. Except as + expressly stated in this notice, no other rights or licenses, express or + implied, are granted by Apple herein, including but not limited to any + patent rights that may be infringed by your derivative works or by other + works in which the Apple Software may be incorporated. + + The Apple Software is provided by Apple on an "AS IS" basis. APPLE + MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION + THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND + OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. + + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, + MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED + AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), + STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + Copyright (C) 2010 Apple Inc. All Rights Reserved. + +*/ + +#import "KeychainItemWrapper.h" +#import + +/* + +These are the default constants and their respective types, +available for the kSecClassGenericPassword Keychain Item class: + +kSecAttrAccessGroup - CFStringRef +kSecAttrCreationDate - CFDateRef +kSecAttrModificationDate - CFDateRef +kSecAttrDescription - CFStringRef +kSecAttrComment - CFStringRef +kSecAttrCreator - CFNumberRef +kSecAttrType - CFNumberRef +kSecAttrLabel - CFStringRef +kSecAttrIsInvisible - CFBooleanRef +kSecAttrIsNegative - CFBooleanRef +kSecAttrAccount - CFStringRef +kSecAttrService - CFStringRef +kSecAttrGeneric - CFDataRef + +See the header file Security/SecItem.h for more details. + +*/ + +@interface KeychainItemWrapper (PrivateMethods) +/* +The decision behind the following two methods (secItemFormatToDictionary and dictionaryToSecItemFormat) was +to encapsulate the transition between what the detail view controller was expecting (NSString *) and what the +Keychain API expects as a validly constructed container class. +*/ +- (NSMutableDictionary *)secItemFormatToDictionary:(NSDictionary *)dictionaryToConvert; +- (NSMutableDictionary *)dictionaryToSecItemFormat:(NSDictionary *)dictionaryToConvert; + +// Updates the item in the keychain, or adds it if it doesn't exist. +- (void)writeToKeychain; + +@end + +@implementation KeychainItemWrapper + +@synthesize keychainItemData, genericPasswordQuery; + +- (id)initWithIdentifier: (NSString *)identifier accessGroup:(NSString *) accessGroup; +{ + if (self = [super init]) + { + // Begin Keychain search setup. The genericPasswordQuery leverages the special user + // defined attribute kSecAttrGeneric to distinguish itself between other generic Keychain + // items which may be included by the same application. + genericPasswordQuery = [[NSMutableDictionary alloc] init]; + + [genericPasswordQuery setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; + [genericPasswordQuery setObject:identifier forKey:(id)kSecAttrGeneric]; + + // The keychain access group attribute determines if this item can be shared + // amongst multiple apps whose code signing entitlements contain the same keychain access group. + if (accessGroup != nil) + { +#if TARGET_IPHONE_SIMULATOR + // Ignore the access group if running on the iPhone simulator. + // + // Apps that are built for the simulator aren't signed, so there's no keychain access group + // for the simulator to check. This means that all apps can see all keychain items when run + // on the simulator. + // + // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the + // simulator will return -25243 (errSecNoAccessForItem). +#else + [genericPasswordQuery setObject:accessGroup forKey:(id)kSecAttrAccessGroup]; +#endif + } + + // Use the proper search constants, return only the attributes of the first match. + [genericPasswordQuery setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit]; + [genericPasswordQuery setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes]; + + NSDictionary *tempQuery = [NSDictionary dictionaryWithDictionary:genericPasswordQuery]; + + NSMutableDictionary *outDictionary = nil; + + if (! SecItemCopyMatching((CFDictionaryRef)tempQuery, (CFTypeRef *)&outDictionary) == noErr) + { + // Stick these default values into keychain item if nothing found. + [self resetKeychainItem]; + + // Add the generic attribute and the keychain access group. + [keychainItemData setObject:identifier forKey:(id)kSecAttrGeneric]; + if (accessGroup != nil) + { +#if TARGET_IPHONE_SIMULATOR + // Ignore the access group if running on the iPhone simulator. + // + // Apps that are built for the simulator aren't signed, so there's no keychain access group + // for the simulator to check. This means that all apps can see all keychain items when run + // on the simulator. + // + // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the + // simulator will return -25243 (errSecNoAccessForItem). +#else + [keychainItemData setObject:accessGroup forKey:(id)kSecAttrAccessGroup]; +#endif + } + } + else + { + // load the saved data from Keychain. + self.keychainItemData = [self secItemFormatToDictionary:outDictionary]; + } + + [outDictionary release]; + } + + return self; +} + +- (void)dealloc +{ + [keychainItemData release]; + [genericPasswordQuery release]; + + [super dealloc]; +} + +- (void)setObject:(id)inObject forKey:(id)key +{ + if (inObject == nil) return; + id currentObject = [keychainItemData objectForKey:key]; + if (![currentObject isEqual:inObject]) + { + [keychainItemData setObject:inObject forKey:key]; + [self writeToKeychain]; + } +} + +- (id)objectForKey:(id)key +{ + return [keychainItemData objectForKey:key]; +} + +- (void)resetKeychainItem +{ + OSStatus junk = noErr; + if (!keychainItemData) + { + self.keychainItemData = [[NSMutableDictionary alloc] init]; + } + else if (keychainItemData) + { + NSMutableDictionary *tempDictionary = [self dictionaryToSecItemFormat:keychainItemData]; + junk = SecItemDelete((CFDictionaryRef)tempDictionary); + NSAssert( junk == noErr || junk == errSecItemNotFound, @"Problem deleting current dictionary." ); + } + + // Default attributes for keychain item. + [keychainItemData setObject:@"" forKey:(id)kSecAttrAccount]; + [keychainItemData setObject:@"" forKey:(id)kSecAttrLabel]; + [keychainItemData setObject:@"" forKey:(id)kSecAttrDescription]; + + // Default data for keychain item. + [keychainItemData setObject:@"" forKey:(id)kSecValueData]; +} + +- (NSMutableDictionary *)dictionaryToSecItemFormat:(NSDictionary *)dictionaryToConvert +{ + // The assumption is that this method will be called with a properly populated dictionary + // containing all the right key/value pairs for a SecItem. + + // Create a dictionary to return populated with the attributes and data. + NSMutableDictionary *returnDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionaryToConvert]; + + // Add the Generic Password keychain item class attribute. + [returnDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; + + // Convert the NSString to NSData to meet the requirements for the value type kSecValueData. + // This is where to store sensitive data that should be encrypted. + NSString *passwordString = [dictionaryToConvert objectForKey:(id)kSecValueData]; + [returnDictionary setObject:[passwordString dataUsingEncoding:NSUTF8StringEncoding] forKey:(id)kSecValueData]; + + return returnDictionary; +} + +- (NSMutableDictionary *)secItemFormatToDictionary:(NSDictionary *)dictionaryToConvert +{ + // The assumption is that this method will be called with a properly populated dictionary + // containing all the right key/value pairs for the UI element. + + // Create a dictionary to return populated with the attributes and data. + NSMutableDictionary *returnDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionaryToConvert]; + + // Add the proper search key and class attribute. + [returnDictionary setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData]; + [returnDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; + + // Acquire the password data from the attributes. + NSData *passwordData = NULL; + if (SecItemCopyMatching((CFDictionaryRef)returnDictionary, (CFTypeRef *)&passwordData) == noErr) + { + // Remove the search, class, and identifier key/value, we don't need them anymore. + [returnDictionary removeObjectForKey:(id)kSecReturnData]; + + // Add the password to the dictionary, converting from NSData to NSString. + NSString *password = [[[NSString alloc] initWithBytes:[passwordData bytes] length:[passwordData length] + encoding:NSUTF8StringEncoding] autorelease]; + [returnDictionary setObject:password forKey:(id)kSecValueData]; + } + else + { + // Don't do anything if nothing is found. + NSAssert(NO, @"Serious error, no matching item found in the keychain.\n"); + } + + [passwordData release]; + + return returnDictionary; +} + +- (void)writeToKeychain +{ + NSDictionary *attributes = NULL; + NSMutableDictionary *updateItem = NULL; + OSStatus result; + + if (SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery, (CFTypeRef *)&attributes) == noErr) + { + // First we need the attributes from the Keychain. + updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes]; + // Second we need to add the appropriate search key/values. + [updateItem setObject:[genericPasswordQuery objectForKey:(id)kSecClass] forKey:(id)kSecClass]; + + // Lastly, we need to set up the updated attribute list being careful to remove the class. + NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainItemData]; + [tempCheck removeObjectForKey:(id)kSecClass]; + +#if TARGET_IPHONE_SIMULATOR + // Remove the access group if running on the iPhone simulator. + // + // Apps that are built for the simulator aren't signed, so there's no keychain access group + // for the simulator to check. This means that all apps can see all keychain items when run + // on the simulator. + // + // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the + // simulator will return -25243 (errSecNoAccessForItem). + // + // The access group attribute will be included in items returned by SecItemCopyMatching, + // which is why we need to remove it before updating the item. + [tempCheck removeObjectForKey:(id)kSecAttrAccessGroup]; +#endif + + // An implicit assumption is that you can only update a single item at a time. + + result = SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)tempCheck); + NSAssert( result == noErr, @"Couldn't update the Keychain Item." ); + } + else + { + // No previous item found; add the new one. + result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL); + NSAssert( result == noErr, @"Couldn't add the Keychain Item." ); + } +} + +@end diff --git a/ManagerDemo/Common/GesturePassword/TentacleView.h b/ManagerDemo/Common/GesturePassword/TentacleView.h new file mode 100755 index 0000000..e2d7359 --- /dev/null +++ b/ManagerDemo/Common/GesturePassword/TentacleView.h @@ -0,0 +1,48 @@ +// +// TentacleView.h +// GesturePassword +// +// Created by hb on 14-8-23. +// Copyright (c) 2014年 黑と白の印记. All rights reserved. +// +#import + +@protocol ResetDelegate + +- (BOOL)resetPassword:(NSString *)result; + +@end + +@protocol VerificationDelegate + +- (BOOL)verification:(NSString *)result; + +@end + +@protocol TouchBeginDelegate + +- (void)gestureTouchBegin; + +@end + + + +@interface TentacleView : UIView + +@property (nonatomic,strong) NSArray * buttonArray; + +@property (nonatomic,assign) id rerificationDelegate; + +@property (nonatomic,assign) id resetDelegate; + +@property (nonatomic,assign) id touchBeginDelegate; + +/* + 1: Verify + 2: Reset + */ +@property (nonatomic,assign) NSInteger style; + +- (void)enterArgin; + +@end diff --git a/ManagerDemo/Common/GesturePassword/TentacleView.m b/ManagerDemo/Common/GesturePassword/TentacleView.m new file mode 100755 index 0000000..bdee212 --- /dev/null +++ b/ManagerDemo/Common/GesturePassword/TentacleView.m @@ -0,0 +1,163 @@ +// +// TentacleView.m +// GesturePassword +// +// Created by hb on 14-8-23. +// Copyright (c) 2014年 黑と白の印记. All rights reserved. +// + +#import "TentacleView.h" +#import "GesturePasswordButton.h" + +@implementation TentacleView { + CGPoint lineStartPoint; + CGPoint lineEndPoint; + + NSMutableArray * touchesArray; + NSMutableArray * touchedArray; + BOOL success; +} +@synthesize buttonArray; +@synthesize rerificationDelegate; +@synthesize resetDelegate; +@synthesize touchBeginDelegate; +@synthesize style; + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + // Initialization code + touchesArray = [[NSMutableArray alloc]initWithCapacity:0]; + touchedArray = [[NSMutableArray alloc]initWithCapacity:0]; + [self setBackgroundColor:[UIColor clearColor]]; + [self setUserInteractionEnabled:YES]; + success = 1; + } + return self; +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ + CGPoint touchPoint; + UITouch *touch = [touches anyObject]; + [touchesArray removeAllObjects]; + [touchedArray removeAllObjects]; + [touchBeginDelegate gestureTouchBegin]; + success=1; + if (touch) { + touchPoint = [touch locationInView:self]; + for (int i=0; i @implementation ManagerUtil ++(void)presentGesturePsw +{ + GesturePasswordController* gesturePasswordController = [[GesturePasswordController alloc] init]; + UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:gesturePasswordController]; + navigationController.navigationBar.translucent = YES; + navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; + + AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate]; + [app.mainViewController presentViewController:navigationController animated:YES completion:^{ + + }]; + + +} +(void)presentLoginView { [ManagerUser shareInstance].isLogin = NO; diff --git a/ManagerDemo/MainView/MyView/AccountInfoViewController.m b/ManagerDemo/MainView/MyView/AccountInfoViewController.m index 159208f..968ce59 100644 --- a/ManagerDemo/MainView/MyView/AccountInfoViewController.m +++ b/ManagerDemo/MainView/MyView/AccountInfoViewController.m @@ -10,6 +10,7 @@ #import "SetPassWordViewController.h" #import "ModifyPassWordViewController.h" #import "AuthenticationViewController.h" +#import "GesturePasswordController.h" @interface AccountInfoViewController () { NSDictionary* _infoDic; @@ -39,6 +40,11 @@ [_bottomBtn addTarget:self action:@selector(modifyTransactionsPassword:) forControlEvents:UIControlEventTouchUpInside]; // [self loadData]; } +-(void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + [_tableView reloadData]; +} -(void)loadData { DaiDaiTongApi* daiDaiTongApi = [DaiDaiTongApi shareInstance]; @@ -145,8 +151,8 @@ cell.imageView.image = [UIImage imageNamed:@"hw_verifycard_info_icon"]; cell.textLabel.text = @"开启手势"; UISwitch *switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(50, 100, 20, 10)]; - [switchButton setOn:YES]; -// [switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged]; + [switchButton setOn:[ManagerUser shareInstance].isGesturePsw]; + [switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged]; cell.accessoryView = switchButton; } @@ -194,6 +200,17 @@ // setPassWordViewController.type = 1; // [self.navigationController pushViewController:setPassWordViewController animated:YES]; } +#pragma mark 手势密码开关 +-(void)switchAction:(id)sender +{ + UISwitch* switchView = (UISwitch*)sender; + [ManagerUser shareInstance].isGesturePsw = switchView.on; + if (switchView.isOn) { + [ManagerUtil presentGesturePsw]; + }else{ + [ManagerUser shareInstance].gesturePsw = @""; + } +} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; diff --git a/ManagerDemo/MainView/MyView/AccountInfoViewController.xib b/ManagerDemo/MainView/MyView/AccountInfoViewController.xib index 35afe44..7fc9737 100644 --- a/ManagerDemo/MainView/MyView/AccountInfoViewController.xib +++ b/ManagerDemo/MainView/MyView/AccountInfoViewController.xib @@ -1,5 +1,5 @@ - + diff --git a/ManagerDemo/MainViewControll/HomeViewController.m b/ManagerDemo/MainViewControll/HomeViewController.m index 232fca7..bb64b7d 100644 --- a/ManagerDemo/MainViewControll/HomeViewController.m +++ b/ManagerDemo/MainViewControll/HomeViewController.m @@ -48,6 +48,9 @@ [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; [_tableView headerBeginRefreshing]; + if ([ManagerUser shareInstance].isLogin && [ManagerUser shareInstance].isGesturePsw) { + [ManagerUtil presentGesturePsw]; + } } -(void)viewDidAppear:(BOOL)animated diff --git a/ManagerDemo/MainViewControll/MoreViewController.m b/ManagerDemo/MainViewControll/MoreViewController.m index 6243daa..06ebe9d 100644 --- a/ManagerDemo/MainViewControll/MoreViewController.m +++ b/ManagerDemo/MainViewControll/MoreViewController.m @@ -251,6 +251,8 @@ { if (buttonIndex == 1) { [ManagerUser shareInstance].isLogin = false; + [ManagerUser shareInstance].isGesturePsw = false; + [ManagerUser shareInstance].gesturePsw = @""; AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate]; [app.mainViewController setSelectedIndex:0]; [_tableView reloadData];