PCSAutherView.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // PCSAutherView.m
  3. // LenzSDK
  4. //
  5. // Created by lr on 2023/4/11.
  6. //
  7. #import "PCSAutherView.h"
  8. #import "UIImage+name.h"
  9. #import <Masonry/Masonry.h>
  10. @interface PCSAutherView()
  11. @property (nonatomic) UIView *centerView;
  12. @property (nonatomic) UIButton *closeButton;
  13. @property (nonatomic) UILabel *titleLabel;
  14. @property (nonatomic) UILabel *subLabel;
  15. @property (nonatomic) UILabel *autherLabel;
  16. @end
  17. @implementation PCSAutherView
  18. - (instancetype)initWithFrame:(CGRect)frame {
  19. if (self = [super initWithFrame:frame]) {
  20. self.backgroundColor = [UIColor whiteColor];
  21. [self addSubview:self.closeButton];
  22. [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  23. make.top.mas_offset(64);
  24. make.right.mas_offset(-10);
  25. make.width.height.mas_offset(44);
  26. }];
  27. [self addSubview:self.titleLabel];
  28. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.center.mas_equalTo(self);
  30. }];
  31. [self addSubview:self.subLabel];
  32. [self.subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.centerX.mas_equalTo(self).mas_offset(-30);
  34. make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(8);
  35. }];
  36. [self addSubview:self.autherLabel];
  37. [self.autherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.left.mas_equalTo(self.subLabel.mas_right);
  39. make.centerY.mas_equalTo(self.subLabel);
  40. make.width.mas_offset(70);
  41. make.height.mas_offset(44);
  42. }];
  43. }
  44. return self;
  45. }
  46. - (void)closeAction {
  47. if (self.closeBlock) {
  48. self.closeBlock();
  49. }
  50. self.hidden = YES;
  51. }
  52. - (void)authButtonAction {
  53. NSURL* url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  54. if(url != nil){
  55. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
  56. }];
  57. }
  58. }
  59. - (void)showAutherWith:(PCSAuthType)type {
  60. NSString *title = @"需要访问相机和麦克风权限,";
  61. if (type == PCSAuthPhone) {
  62. title = @"需要访问相机权限,";
  63. } else if (type == PCSAuthMir) {
  64. title = @"需要访问麦克风权限,";
  65. }
  66. self.hidden = NO;
  67. self.subLabel.text = title;
  68. }
  69. - (UIButton *)closeButton {
  70. if (!_closeButton) {
  71. _closeButton = [[UIButton alloc]init];
  72. [_closeButton setImage:[UIImage loadNamed:@"icon_close"] forState:UIControlStateNormal];
  73. [_closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  74. }
  75. return _closeButton;
  76. }
  77. - (UILabel *)titleLabel {
  78. if (!_titleLabel) {
  79. _titleLabel = [[UILabel alloc]init];
  80. _titleLabel.text = @"未获得授权";
  81. _titleLabel.textColor = [UIColor blackColor];
  82. _titleLabel.font = [UIFont systemFontOfSize:14];
  83. }
  84. return _titleLabel;
  85. }
  86. - (UILabel *)subLabel {
  87. if (!_subLabel) {
  88. _subLabel = [[UILabel alloc]init];
  89. _subLabel.textColor = [UIColor blackColor];
  90. _subLabel.font = [UIFont systemFontOfSize:14];
  91. }
  92. return _subLabel;
  93. }
  94. - (UILabel *)autherLabel {
  95. if (!_autherLabel) {
  96. _autherLabel = [[UILabel alloc]init];
  97. _autherLabel.textColor = [UIColor blackColor];
  98. _autherLabel.font = [UIFont systemFontOfSize:14];
  99. _autherLabel.text = @"去开启 >";
  100. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(authButtonAction)];
  101. [_autherLabel addGestureRecognizer:tap];
  102. _autherLabel.textAlignment = NSTextAlignmentLeft;
  103. _autherLabel.textColor = [UIColor colorWithRed:231/255.0 green:108/255.0 blue:30/255.0 alpha:1];
  104. _autherLabel.userInteractionEnabled = YES;
  105. }
  106. return _autherLabel;
  107. }
  108. @end