No Description

KXPrivacyView.m 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. //
  2. // KXPrivacyView.m
  3. // CAISHEN
  4. //
  5. // Created by admin on 2018/10/9.
  6. // Copyright © 2018 kuxuan. All rights reserved.
  7. //
  8. #import "KXPrivacyView.h"
  9. #import "KXCustomWebViewController.h"
  10. #import "KXHomeViewController.h"
  11. #import "KXHomeNavgationController.h"
  12. @interface KXPrivacyView ()
  13. @property (nonatomic, strong) UIView *whiteView;
  14. @property (nonatomic, strong) UIImageView *topImageView;
  15. @property (nonatomic, strong) UIView *backView;
  16. @property (nonatomic, copy) NSString *privacyUrl;
  17. @end
  18. @implementation KXPrivacyView
  19. - (instancetype)initWithFrame:(CGRect)frame privacyUrl:(NSString *)url{
  20. if (self = [super initWithFrame:frame]) {
  21. self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
  22. self.privacyUrl = url;
  23. self.backView = [[UIView alloc] init];
  24. self.backView.backgroundColor = [UIColor clearColor];
  25. [self addSubview:self.backView];
  26. [self.backView addSubview:self.whiteView];
  27. [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.left.equalTo(self.mas_left).offset(20);
  29. make.right.equalTo(self.mas_right).offset(-20);
  30. make.centerX.equalTo(self.mas_centerX);
  31. make.centerY.equalTo(self.mas_centerY);
  32. make.height.equalTo(330);
  33. }];
  34. [self.whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.equalTo(self.backView.mas_left);
  36. make.right.equalTo(self.backView.mas_right);
  37. make.top.equalTo(self.backView.mas_top).offset(30);
  38. make.bottom.equalTo(self.backView.mas_bottom);
  39. }];
  40. self.topImageView = [[UIImageView alloc] init];
  41. self.topImageView.image = [UIImage imageNamed:@"mine_about"];
  42. self.topImageView.layer.cornerRadius = 30;
  43. self.topImageView.layer.masksToBounds = YES;
  44. [self.backView addSubview:self.topImageView];
  45. [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.centerX.equalTo(self.backView.mas_centerX);
  47. make.size.equalTo(CGSizeMake(60, 60));
  48. make.top.equalTo(self.backView.mas_top);
  49. }];
  50. [self setUpWhiteViewContentView];
  51. }
  52. return self;
  53. }
  54. - (void)setUpWhiteViewContentView{
  55. for (UIView *view in self.whiteView.subviews) {
  56. [view removeFromSuperview];
  57. }
  58. [self.backView mas_updateConstraints:^(MASConstraintMaker *make) {
  59. make.height.equalTo(330);
  60. }];
  61. [self.backView layoutIfNeeded];
  62. UILabel *titleLabel = [[UILabel alloc] init];
  63. titleLabel.textColor = [UIColor titleColor];
  64. titleLabel.font = FONT_BOLD(15);
  65. titleLabel.text = [NSString stringWithFormat:@"%@隐私政策",[NSString getAppName]];
  66. [self.whiteView addSubview:titleLabel];
  67. UILabel *contentLabel = [[UILabel alloc] init];
  68. contentLabel.numberOfLines = 0;
  69. NSString *contengString = [NSString stringWithFormat:@"欢迎使用“%@”!我们非常重视您的个人信息和隐私保护。在您使用“%@”服务之前,请仔细阅读《%@隐私政策》,我们将严格按照经您同意的各项条款使用您的个人信息,以便为您提供更好的服务。",[NSString getAppName],[NSString getAppName],[NSString getAppName]];
  70. NSMutableAttributedString *attibuteString = [[NSMutableAttributedString alloc] initWithString:contengString attributes:@{NSForegroundColorAttributeName:[UIColor KXColorWithHex:0x666666],NSFontAttributeName:FONT_SYS(14)}];
  71. NSUInteger appNameLenth = [NSString getAppName].length;
  72. [attibuteString addAttributes:@{NSForegroundColorAttributeName:[UIColor baseColor],NSFontAttributeName:FONT_SYS(13)} range:NSMakeRange(41+appNameLenth*2, appNameLenth+6)];
  73. contentLabel.userInteractionEnabled = YES;
  74. [contentLabel setAttributedText:attibuteString];
  75. // 点击方法
  76. [contentLabel bk_whenTapped:^{
  77. KXCustomWebViewController *webVC = [[KXCustomWebViewController alloc] init];
  78. webVC.webStr = self.privacyUrl;
  79. webVC.title = @"隐私政策";
  80. KXHomeViewController *homeVC = (KXHomeViewController *)[UIApplication sharedApplication].keyWindow.rootViewController;
  81. KXHomeNavgationController *navVC = (KXHomeNavgationController *)homeVC.viewControllers.firstObject;
  82. KXHomeNavgationController *nav = [[KXHomeNavgationController alloc] initWithRootViewController:webVC];
  83. [navVC presentViewController:nav animated:YES completion:^{
  84. }];
  85. }];
  86. [contentLabel sizeToFit];
  87. [self.whiteView addSubview:contentLabel];
  88. UILabel *detailLabel = [[UILabel alloc] init];
  89. detailLabel.textColor = [UIColor detailTitleColor];
  90. detailLabel.font = FONT_SYS(13);
  91. detailLabel.numberOfLines = 0;
  92. detailLabel.text = @"如您同意此政策,请点击“同意”并开始使用我们的产品和服务,我们会尽全力保护您的个人信息安全";
  93. [detailLabel sizeToFit];
  94. [self.whiteView addSubview:detailLabel];
  95. UIButton *noAgreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  96. noAgreeBtn.backgroundColor = [UIColor whiteColor];
  97. [noAgreeBtn setTitle:@"不同意" forState:UIControlStateNormal];
  98. [noAgreeBtn setTitleColor:[UIColor KXColorWithHex:0x666666] forState:UIControlStateNormal];
  99. noAgreeBtn.layer.borderColor = [UIColor detailTitleColor].CGColor;
  100. noAgreeBtn.layer.borderWidth = 0.4;
  101. noAgreeBtn.tag = KXPrivacyViewButtonStyleFirstNoAgree;
  102. [noAgreeBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  103. [self.whiteView addSubview:noAgreeBtn];
  104. UIButton *agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  105. agreeBtn.backgroundColor = [UIColor baseColor];
  106. [agreeBtn setTitle:@"同意" forState:UIControlStateNormal];
  107. [agreeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  108. agreeBtn.tag = KXPrivacyViewButtonStyleFirstAgree;
  109. [agreeBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  110. [self.whiteView addSubview:agreeBtn];
  111. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.centerX.equalTo(self.whiteView.mas_centerX);
  113. make.top.equalTo(self.whiteView.mas_top).offset(50);
  114. }];
  115. [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.left.equalTo(self.whiteView.mas_left).offset(10);
  117. make.right.equalTo(self.whiteView.mas_right).offset(-10);
  118. make.top.equalTo(titleLabel.mas_bottom).offset(20);
  119. }];
  120. [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.left.equalTo(self.whiteView.mas_left).offset(10);
  122. make.right.equalTo(self.whiteView.mas_right).offset(-10);
  123. make.top.equalTo(contentLabel.mas_bottom).offset(20);
  124. }];
  125. [noAgreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.left.equalTo(self.whiteView.mas_left).offset(10);
  127. make.bottom.equalTo(self.whiteView.mas_bottom).offset(-10);
  128. make.size.equalTo(CGSizeMake((SCREEN_WIDTH-70)/2, 50));
  129. }];
  130. [agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.right.equalTo(self.whiteView.mas_right).offset(-10);
  132. make.bottom.equalTo(noAgreeBtn.mas_bottom);
  133. make.size.equalTo(CGSizeMake((SCREEN_WIDTH-70)/2, 50));
  134. }];
  135. [self addAnimation];
  136. }
  137. - (void)setPrivaceView{
  138. for (UIView *view in self.whiteView.subviews) {
  139. [view removeFromSuperview];
  140. }
  141. [self.backView mas_updateConstraints:^(MASConstraintMaker *make) {
  142. make.height.equalTo(280);
  143. }];
  144. [self.backView layoutIfNeeded];
  145. UILabel *titleLabel = [[UILabel alloc] init];
  146. titleLabel.textColor = [UIColor titleColor];
  147. titleLabel.font = FONT_BOLD(15);
  148. titleLabel.text = @"隐私保护提示";
  149. [self.whiteView addSubview:titleLabel];
  150. UILabel *detailLabel = [[UILabel alloc] init];
  151. detailLabel.textColor = [UIColor detailTitleColor];
  152. detailLabel.font = FONT_SYS(13);
  153. detailLabel.numberOfLines = 0;
  154. detailLabel.text = [NSString stringWithFormat:@"请放心,%@坚决保障您的隐私信息安全,您的信息仅用于为您提供服务或改善服务体验。如果您确实无法认同此政策,可点击“不同意”并退出应用",[NSString getAppName]];
  155. [detailLabel sizeToFit];
  156. [self.whiteView addSubview:detailLabel];
  157. UIButton *noAgreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  158. noAgreeBtn.backgroundColor = [UIColor whiteColor];
  159. [noAgreeBtn setTitle:@"不同意并退出" forState:UIControlStateNormal];
  160. [noAgreeBtn setTitleColor:[UIColor KXColorWithHex:0x666666] forState:UIControlStateNormal];
  161. noAgreeBtn.layer.borderColor = [UIColor detailTitleColor].CGColor;
  162. noAgreeBtn.layer.borderWidth = 0.4;
  163. noAgreeBtn.tag = KXPrivacyViewButtonStyleNextAgree;
  164. [noAgreeBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  165. [self.whiteView addSubview:noAgreeBtn];
  166. UIButton *agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  167. agreeBtn.backgroundColor = [UIColor baseColor];
  168. [agreeBtn setTitle:@"再想想" forState:UIControlStateNormal];
  169. [agreeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  170. agreeBtn.tag = KXPrivacyViewButtonStyleNextNoAgree;
  171. [agreeBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  172. [self.whiteView addSubview:agreeBtn];
  173. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  174. make.centerX.equalTo(self.whiteView.mas_centerX);
  175. make.top.equalTo(self.whiteView.mas_top).offset(50);
  176. }];
  177. [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  178. make.left.equalTo(self.whiteView.mas_left).offset(10);
  179. make.right.equalTo(self.whiteView.mas_right).offset(-10);
  180. make.top.equalTo(titleLabel.mas_bottom).offset(20);
  181. }];
  182. [noAgreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.left.equalTo(self.whiteView.mas_left).offset(10);
  184. make.bottom.equalTo(self.whiteView.mas_bottom).offset(-10);
  185. make.size.equalTo(CGSizeMake((SCREEN_WIDTH-70)/2, 50));
  186. }];
  187. [agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  188. make.right.equalTo(self.whiteView.mas_right).offset(-10);
  189. make.bottom.equalTo(noAgreeBtn.mas_bottom);
  190. make.size.equalTo(CGSizeMake((SCREEN_WIDTH-70)/2, 50));
  191. }];
  192. [self addAnimation];
  193. }
  194. - (void)buttonClick:(UIButton *)btn{
  195. switch (btn.tag) {
  196. case KXPrivacyViewButtonStyleFirstNoAgree:
  197. [self setPrivaceView];
  198. break;
  199. case KXPrivacyViewButtonStyleFirstAgree:
  200. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kPrivacyAgreeStatus];
  201. [[NSUserDefaults standardUserDefaults] synchronize];
  202. [self removeFromSuperview];
  203. break;
  204. case KXPrivacyViewButtonStyleNextNoAgree:
  205. [self setUpWhiteViewContentView];
  206. break;
  207. case KXPrivacyViewButtonStyleNextAgree:
  208. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kPrivacyAgreeStatus];
  209. [[NSUserDefaults standardUserDefaults] synchronize];
  210. exit(0);
  211. break;
  212. default:
  213. break;
  214. }
  215. }
  216. - (void)addAnimation{
  217. CAKeyframeAnimation * animation;
  218. animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
  219. animation.duration = 0.75;
  220. animation.removedOnCompletion = NO;
  221. animation.fillMode = kCAFillModeForwards;
  222. NSMutableArray *values = [NSMutableArray array];
  223. [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
  224. [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
  225. [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
  226. [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
  227. animation.values = values;
  228. animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
  229. [self.backView.layer addAnimation:animation forKey:nil];
  230. }
  231. #pragma mark - 懒加载
  232. - (UIView *)whiteView{
  233. if (!_whiteView) {
  234. _whiteView = [[UIView alloc] init];
  235. _whiteView.backgroundColor = [UIColor whiteColor];
  236. _whiteView.layer.cornerRadius = 6;
  237. _whiteView.layer.masksToBounds = YES;
  238. }
  239. return _whiteView;
  240. }
  241. @end