BDFaceSelectConfigController.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // BDFaceSelectConfigController.m
  3. // FaceSDKSample_IOS
  4. //
  5. // Created by Zhang,Jian(MBD) on 2020/12/1.
  6. // Copyright © 2020 Baidu. All rights reserved.
  7. //
  8. #import "BDFaceSelectConfigController.h"
  9. #import "BDFaceSelectItem.h"
  10. #import "BDFaceSelectConfigCell.h"
  11. #import "BDFaceSelectRadio.h"
  12. #import "BDFaceSelectItem.h"
  13. #import "BDFaceAdjustParamsFileManager.h"
  14. #import "BDFaceAdjustParamsConstants.h"
  15. #import "BDFaceAdjustParamsController.h"
  16. #import "UIColor+BDFaceColorUtils.h"
  17. #import "BDFaceSelectConfigModel.h"
  18. #import "BDFaceAdjustParamsTool.h"
  19. static NSString *const BDFaceSelectConfigControllerTitle = @"质量控制设置";
  20. static float const BDFaceSelectConfigTableViewHeight = 24.0f;
  21. static NSString *const BDFaceSelectConfigControllerTip1 = @"实名认证场景推荐使用[严格] 或 [正常]模式";
  22. static NSString *const BDFaceSelectConfigControllerTip2 = @"人脸对比场景推荐使用[正常] 或 [宽松]模式";
  23. @interface BDFaceSelectConfigController ()
  24. @property(nonatomic, strong) NSMutableArray *allData;
  25. @end
  26. @implementation BDFaceSelectConfigController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. self.allData = [BDFaceSelectConfigModel loadItems];
  31. [self loadTableWithCellClass:[BDFaceSelectConfigCell class] reuseLabel:NSStringFromClass([BDFaceSelectConfigCell class]) dataSourceArray:self.allData];
  32. CGRect tableRect = self.tableView.frame;
  33. tableRect.origin.x = BDFaceAdjustConfigTableMargin;
  34. tableRect.size.width = CGRectGetWidth(self.view.frame) - BDFaceAdjustConfigTableMargin * 2.0f;
  35. self.tableView.frame = tableRect;
  36. self.titleLabel.text = BDFaceSelectConfigControllerTitle;
  37. }
  38. - (void)viewWillAppear:(BOOL)animated {
  39. [self.tableView reloadData];
  40. }
  41. - (void)dealloc
  42. {
  43. [[NSNotificationCenter defaultCenter] removeObserver:self];
  44. }
  45. - (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  46. CGRect rect = CGRectMake(0, 0, CGRectGetWidth(self.view.frame) - BDFaceAdjustConfigTableMargin * 2.0f, BDFaceSelectConfigTableViewHeight * 3);
  47. UIView *view = [[UIView alloc] initWithFrame:rect];
  48. CGRect label1Rect = rect;
  49. label1Rect.origin.y = BDFaceSelectConfigTableViewHeight;
  50. label1Rect.size.height = BDFaceSelectConfigTableViewHeight;
  51. UILabel *label1 = [[UILabel alloc] initWithFrame:label1Rect];
  52. [view addSubview:label1];
  53. CGRect label2Rect = label1Rect;
  54. label2Rect.origin.y = CGRectGetMaxY(label1Rect);
  55. UILabel *label2 = [[UILabel alloc] initWithFrame:label2Rect];
  56. [view addSubview:label2];
  57. label1.textColor = [UIColor face_colorWithRGBHex:BDFaceAdjustConfigTipTextColor];
  58. label2.textColor = [UIColor face_colorWithRGBHex:BDFaceAdjustConfigTipTextColor];
  59. label1.text = BDFaceSelectConfigControllerTip1;
  60. label2.text = BDFaceSelectConfigControllerTip2;
  61. label1.font = [UIFont systemFontOfSize:14.0f];
  62. label2.font = [UIFont systemFontOfSize:14.0f];
  63. return view;
  64. }
  65. - (UITableViewStyle)customTableViewStyle {
  66. return UITableViewStyleGrouped;
  67. }
  68. - (void)updateCellContent:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
  69. BDFaceSelectConfigCell *theCell;
  70. if ([cell isKindOfClass:[BDFaceSelectConfigCell class]]) {
  71. theCell = (BDFaceSelectConfigCell *)cell;
  72. if (indexPath.section == 0){
  73. if (indexPath.row == [BDFaceAdjustParamsFileManager sharedInstance].selectType) {
  74. [theCell.radio initRadioState:YES];
  75. [theCell showSettingButton:YES];
  76. } else {
  77. [theCell.radio initRadioState:NO];
  78. [theCell showSettingButton:NO];
  79. }
  80. }
  81. }
  82. __weak typeof(self) this = self;
  83. if (theCell) {
  84. theCell.adjustConfigAction = ^(BDFaceSelectType type) {
  85. BDFaceAdjustParamsController *adjustController = [[BDFaceAdjustParamsController alloc] initWithConfig:[[BDFaceAdjustParamsFileManager sharedInstance] configBySelection:type]];
  86. [this.navigationController pushViewController:adjustController animated:YES];
  87. };
  88. }
  89. }
  90. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  91. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  92. if ([cell isKindOfClass:[BDFaceSelectConfigCell class]]) {
  93. BDFaceSelectConfigCell *theCell = (BDFaceSelectConfigCell *)cell;
  94. [theCell.radio changeRadioState:YES];
  95. BDFaceSelectType typeChoosed = (BDFaceSelectType)indexPath.row;
  96. [BDFaceAdjustParamsFileManager sharedInstance].selectType = typeChoosed;
  97. BDFaceAdjustParams *params = [[BDFaceAdjustParamsFileManager sharedInstance] configBySelection:typeChoosed];
  98. [BDFaceAdjustParamsTool changeConfig:params];
  99. }
  100. }
  101. - (void)goBack {
  102. [self.navigationController popViewControllerAnimated:YES];
  103. }
  104. @end