123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- //
- // KXPrivacyView.m
- // CAISHEN
- //
- // Created by admin on 2018/10/9.
- // Copyright © 2018 kuxuan. All rights reserved.
- //
- #import "KXPrivacyView.h"
- #import "KXCustomWebViewController.h"
- #import "KXHomeViewController.h"
- #import "KXHomeNavgationController.h"
- @interface KXPrivacyView ()
- @property (nonatomic, strong) UIView *whiteView;
- @property (nonatomic, strong) UIImageView *topImageView;
- @property (nonatomic, strong) UIView *backView;
- @property (nonatomic, copy) NSString *privacyUrl;
- @end
- @implementation KXPrivacyView
- - (instancetype)initWithFrame:(CGRect)frame privacyUrl:(NSString *)url{
- if (self = [super initWithFrame:frame]) {
- self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
- self.privacyUrl = url;
- self.backView = [[UIView alloc] init];
- self.backView.backgroundColor = [UIColor clearColor];
- [self addSubview:self.backView];
- [self.backView addSubview:self.whiteView];
- [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.mas_left).offset(20);
- make.right.equalTo(self.mas_right).offset(-20);
- make.centerX.equalTo(self.mas_centerX);
- make.centerY.equalTo(self.mas_centerY);
- make.height.equalTo(330);
- }];
- [self.whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.backView.mas_left);
- make.right.equalTo(self.backView.mas_right);
- make.top.equalTo(self.backView.mas_top).offset(30);
- make.bottom.equalTo(self.backView.mas_bottom);
- }];
- self.topImageView = [[UIImageView alloc] init];
- self.topImageView.image = [UIImage imageNamed:@"mine_about"];
- self.topImageView.layer.cornerRadius = 30;
- self.topImageView.layer.masksToBounds = YES;
- [self.backView addSubview:self.topImageView];
- [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.backView.mas_centerX);
- make.size.equalTo(CGSizeMake(60, 60));
- make.top.equalTo(self.backView.mas_top);
- }];
- [self setUpWhiteViewContentView];
- }
- return self;
- }
- - (void)setUpWhiteViewContentView{
- for (UIView *view in self.whiteView.subviews) {
- [view removeFromSuperview];
- }
- [self.backView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(330);
- }];
- [self.backView layoutIfNeeded];
- UILabel *titleLabel = [[UILabel alloc] init];
- titleLabel.textColor = [UIColor titleColor];
- titleLabel.font = FONT_BOLD(15);
- titleLabel.text = [NSString stringWithFormat:@"%@隐私政策",[NSString getAppName]];
- [self.whiteView addSubview:titleLabel];
-
- UILabel *contentLabel = [[UILabel alloc] init];
- contentLabel.numberOfLines = 0;
- NSString *contengString = [NSString stringWithFormat:@"欢迎使用“%@”!我们非常重视您的个人信息和隐私保护。在您使用“%@”服务之前,请仔细阅读《%@隐私政策》,我们将严格按照经您同意的各项条款使用您的个人信息,以便为您提供更好的服务。",[NSString getAppName],[NSString getAppName],[NSString getAppName]];
- NSMutableAttributedString *attibuteString = [[NSMutableAttributedString alloc] initWithString:contengString attributes:@{NSForegroundColorAttributeName:[UIColor KXColorWithHex:0x666666],NSFontAttributeName:FONT_SYS(14)}];
- NSUInteger appNameLenth = [NSString getAppName].length;
- [attibuteString addAttributes:@{NSForegroundColorAttributeName:[UIColor baseColor],NSFontAttributeName:FONT_SYS(13)} range:NSMakeRange(41+appNameLenth*2, appNameLenth+6)];
- contentLabel.userInteractionEnabled = YES;
- [contentLabel setAttributedText:attibuteString];
- // 点击方法
- [contentLabel bk_whenTapped:^{
- KXCustomWebViewController *webVC = [[KXCustomWebViewController alloc] init];
- webVC.webStr = self.privacyUrl;
- webVC.title = @"隐私政策";
- KXHomeViewController *homeVC = (KXHomeViewController *)[UIApplication sharedApplication].keyWindow.rootViewController;
- KXHomeNavgationController *navVC = (KXHomeNavgationController *)homeVC.viewControllers.firstObject;
- KXHomeNavgationController *nav = [[KXHomeNavgationController alloc] initWithRootViewController:webVC];
- [navVC presentViewController:nav animated:YES completion:^{
-
- }];
- }];
- [contentLabel sizeToFit];
- [self.whiteView addSubview:contentLabel];
-
- UILabel *detailLabel = [[UILabel alloc] init];
- detailLabel.textColor = [UIColor detailTitleColor];
- detailLabel.font = FONT_SYS(13);
- detailLabel.numberOfLines = 0;
- detailLabel.text = @"如您同意此政策,请点击“同意”并开始使用我们的产品和服务,我们会尽全力保护您的个人信息安全";
- [detailLabel sizeToFit];
- [self.whiteView addSubview:detailLabel];
-
- UIButton *noAgreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- noAgreeBtn.backgroundColor = [UIColor whiteColor];
- [noAgreeBtn setTitle:@"不同意" forState:UIControlStateNormal];
- [noAgreeBtn setTitleColor:[UIColor KXColorWithHex:0x666666] forState:UIControlStateNormal];
- noAgreeBtn.layer.borderColor = [UIColor detailTitleColor].CGColor;
- noAgreeBtn.layer.borderWidth = 0.4;
- noAgreeBtn.tag = KXPrivacyViewButtonStyleFirstNoAgree;
- [noAgreeBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.whiteView addSubview:noAgreeBtn];
-
- UIButton *agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- agreeBtn.backgroundColor = [UIColor baseColor];
- [agreeBtn setTitle:@"同意" forState:UIControlStateNormal];
- [agreeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- agreeBtn.tag = KXPrivacyViewButtonStyleFirstAgree;
- [agreeBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.whiteView addSubview:agreeBtn];
- [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.whiteView.mas_centerX);
- make.top.equalTo(self.whiteView.mas_top).offset(50);
- }];
- [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.whiteView.mas_left).offset(10);
- make.right.equalTo(self.whiteView.mas_right).offset(-10);
- make.top.equalTo(titleLabel.mas_bottom).offset(20);
- }];
- [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.whiteView.mas_left).offset(10);
- make.right.equalTo(self.whiteView.mas_right).offset(-10);
- make.top.equalTo(contentLabel.mas_bottom).offset(20);
- }];
- [noAgreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.whiteView.mas_left).offset(10);
- make.bottom.equalTo(self.whiteView.mas_bottom).offset(-10);
- make.size.equalTo(CGSizeMake((SCREEN_WIDTH-70)/2, 50));
- }];
- [agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.whiteView.mas_right).offset(-10);
- make.bottom.equalTo(noAgreeBtn.mas_bottom);
- make.size.equalTo(CGSizeMake((SCREEN_WIDTH-70)/2, 50));
- }];
- [self addAnimation];
- }
- - (void)setPrivaceView{
- for (UIView *view in self.whiteView.subviews) {
- [view removeFromSuperview];
- }
- [self.backView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(280);
- }];
- [self.backView layoutIfNeeded];
- UILabel *titleLabel = [[UILabel alloc] init];
- titleLabel.textColor = [UIColor titleColor];
- titleLabel.font = FONT_BOLD(15);
- titleLabel.text = @"隐私保护提示";
- [self.whiteView addSubview:titleLabel];
-
- UILabel *detailLabel = [[UILabel alloc] init];
- detailLabel.textColor = [UIColor detailTitleColor];
- detailLabel.font = FONT_SYS(13);
- detailLabel.numberOfLines = 0;
- detailLabel.text = [NSString stringWithFormat:@"请放心,%@坚决保障您的隐私信息安全,您的信息仅用于为您提供服务或改善服务体验。如果您确实无法认同此政策,可点击“不同意”并退出应用",[NSString getAppName]];
- [detailLabel sizeToFit];
- [self.whiteView addSubview:detailLabel];
- UIButton *noAgreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- noAgreeBtn.backgroundColor = [UIColor whiteColor];
- [noAgreeBtn setTitle:@"不同意并退出" forState:UIControlStateNormal];
- [noAgreeBtn setTitleColor:[UIColor KXColorWithHex:0x666666] forState:UIControlStateNormal];
- noAgreeBtn.layer.borderColor = [UIColor detailTitleColor].CGColor;
- noAgreeBtn.layer.borderWidth = 0.4;
- noAgreeBtn.tag = KXPrivacyViewButtonStyleNextAgree;
- [noAgreeBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.whiteView addSubview:noAgreeBtn];
-
- UIButton *agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- agreeBtn.backgroundColor = [UIColor baseColor];
- [agreeBtn setTitle:@"再想想" forState:UIControlStateNormal];
- [agreeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- agreeBtn.tag = KXPrivacyViewButtonStyleNextNoAgree;
- [agreeBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.whiteView addSubview:agreeBtn];
- [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.whiteView.mas_centerX);
- make.top.equalTo(self.whiteView.mas_top).offset(50);
- }];
- [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.whiteView.mas_left).offset(10);
- make.right.equalTo(self.whiteView.mas_right).offset(-10);
- make.top.equalTo(titleLabel.mas_bottom).offset(20);
- }];
- [noAgreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.whiteView.mas_left).offset(10);
- make.bottom.equalTo(self.whiteView.mas_bottom).offset(-10);
- make.size.equalTo(CGSizeMake((SCREEN_WIDTH-70)/2, 50));
- }];
- [agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.whiteView.mas_right).offset(-10);
- make.bottom.equalTo(noAgreeBtn.mas_bottom);
- make.size.equalTo(CGSizeMake((SCREEN_WIDTH-70)/2, 50));
- }];
- [self addAnimation];
- }
- - (void)buttonClick:(UIButton *)btn{
- switch (btn.tag) {
- case KXPrivacyViewButtonStyleFirstNoAgree:
- [self setPrivaceView];
- break;
- case KXPrivacyViewButtonStyleFirstAgree:
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kPrivacyAgreeStatus];
- [[NSUserDefaults standardUserDefaults] synchronize];
- [self removeFromSuperview];
- break;
- case KXPrivacyViewButtonStyleNextNoAgree:
- [self setUpWhiteViewContentView];
- break;
- case KXPrivacyViewButtonStyleNextAgree:
- [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kPrivacyAgreeStatus];
- [[NSUserDefaults standardUserDefaults] synchronize];
- exit(0);
- break;
- default:
- break;
- }
- }
- - (void)addAnimation{
- CAKeyframeAnimation * animation;
- animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
- animation.duration = 0.75;
- animation.removedOnCompletion = NO;
-
- animation.fillMode = kCAFillModeForwards;
-
- NSMutableArray *values = [NSMutableArray array];
- [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
- [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
- [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
- [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
-
- animation.values = values;
- animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
-
- [self.backView.layer addAnimation:animation forKey:nil];
- }
- #pragma mark - 懒加载
- - (UIView *)whiteView{
- if (!_whiteView) {
- _whiteView = [[UIView alloc] init];
- _whiteView.backgroundColor = [UIColor whiteColor];
- _whiteView.layer.cornerRadius = 6;
- _whiteView.layer.masksToBounds = YES;
- }
- return _whiteView;
- }
- @end
|