// // 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