PCSAutherView.m 3.7 KB

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