PCSAutherView.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. dispatch_async(dispatch_get_main_queue(), ^{
  61. NSString *title = @"需要访问相机和麦克风权限,";
  62. if (type == PCSAuthPhone) {
  63. title = @"需要访问相机权限,";
  64. } else if (type == PCSAuthMir) {
  65. title = @"需要访问麦克风权限,";
  66. }
  67. self.hidden = NO;
  68. self.subLabel.text = title;
  69. });
  70. }
  71. - (UIButton *)closeButton {
  72. if (!_closeButton) {
  73. _closeButton = [[UIButton alloc]init];
  74. [_closeButton setImage:[UIImage loadNamed:@"icon_close"] forState:UIControlStateNormal];
  75. [_closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  76. }
  77. return _closeButton;
  78. }
  79. - (UILabel *)titleLabel {
  80. if (!_titleLabel) {
  81. _titleLabel = [[UILabel alloc]init];
  82. _titleLabel.text = @"未获得授权";
  83. _titleLabel.textColor = [UIColor blackColor];
  84. _titleLabel.font = [UIFont systemFontOfSize:14];
  85. }
  86. return _titleLabel;
  87. }
  88. - (UILabel *)subLabel {
  89. if (!_subLabel) {
  90. _subLabel = [[UILabel alloc]init];
  91. _subLabel.textColor = [UIColor blackColor];
  92. _subLabel.font = [UIFont systemFontOfSize:14];
  93. }
  94. return _subLabel;
  95. }
  96. - (UILabel *)autherLabel {
  97. if (!_autherLabel) {
  98. _autherLabel = [[UILabel alloc]init];
  99. _autherLabel.textColor = [UIColor blackColor];
  100. _autherLabel.font = [UIFont systemFontOfSize:14];
  101. _autherLabel.text = @"去开启 >";
  102. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(authButtonAction)];
  103. [_autherLabel addGestureRecognizer:tap];
  104. _autherLabel.textAlignment = NSTextAlignmentLeft;
  105. _autherLabel.textColor = [UIColor colorWithRed:231/255.0 green:108/255.0 blue:30/255.0 alpha:1];
  106. _autherLabel.userInteractionEnabled = YES;
  107. }
  108. return _autherLabel;
  109. }
  110. @end