|
|
|
//
|
|
|
|
// jjcdViewController.m
|
|
|
|
// tongxin
|
|
|
|
//
|
|
|
|
// Created by ecell on 2022/11/23.
|
|
|
|
// Copyright © 2022 xTT. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "jjcdViewController.h"
|
|
|
|
#import <SDWebImage/UIButton+WebCache.h>
|
|
|
|
|
|
|
|
@interface jjcdViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
|
|
|
|
|
|
|
|
@property (strong, nonatomic) User *editUser;
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UIButton *codeBtn;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation jjcdViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
|
|
|
|
self.zx_navTitle = @"分享图片";
|
|
|
|
|
|
|
|
UIView *bgView = [UIView new];
|
|
|
|
bgView.backgroundColor = UIColor.whiteColor;
|
|
|
|
bgView.layer.cornerRadius = 5;
|
|
|
|
bgView.layer.shadowColor = RGBA(58, 162, 245, .5).CGColor;
|
|
|
|
bgView.layer.shadowOffset = CGSizeMake(0, 0);
|
|
|
|
bgView.layer.shadowOpacity = 0.5;
|
|
|
|
bgView.layer.shadowRadius = 5;
|
|
|
|
[self.view addSubview:bgView];
|
|
|
|
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.centerX.equalTo(self.view);
|
|
|
|
make.top.equalTo(self.view).offset(Adapted(25));
|
|
|
|
make.size.mas_equalTo(CGSizeMake(Adapted(200), Adapted(200)));
|
|
|
|
}];
|
|
|
|
|
|
|
|
UIButton *codeBtn = [UIButton new];
|
|
|
|
[codeBtn setImage:[UIImage imageNamed:@"jkcode_bg"] forState:0];
|
|
|
|
[codeBtn addTarget:self action:@selector(selectCodeImg) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
self.codeBtn = codeBtn;
|
|
|
|
[bgView addSubview:codeBtn];
|
|
|
|
[codeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.top.equalTo(bgView).offset(Adapted(20));
|
|
|
|
make.right.equalTo(bgView.mas_right).offset(-Adapted(20));
|
|
|
|
make.bottom.equalTo(bgView.mas_bottom).offset(-Adapted(20));
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
UILabel *titleLabel = [UILabel new];
|
|
|
|
titleLabel.text = @"绑定步骤:\n1、把分享图片保存到手机本地;\n2、点击上方二维码区域,选择分享图片进行裁剪;\n3、点击下方设置按钮,将分享图片设置到设备;";
|
|
|
|
titleLabel.font = [UIFont systemFontOfSize:15];
|
|
|
|
titleLabel.textColor = [UIColor lightGrayColor];
|
|
|
|
titleLabel.textAlignment = NSTextAlignmentLeft;
|
|
|
|
titleLabel.numberOfLines = 0;
|
|
|
|
[self.view addSubview:titleLabel];
|
|
|
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.top.equalTo(bgView.mas_bottom).offset(Adapted(40));
|
|
|
|
make.left.equalTo(self.view).offset(Adapted(15));
|
|
|
|
make.right.equalTo(self.view.mas_right).offset(-Adapted(15));
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
[btn setTitle:@"设置" forState:UIControlStateNormal];
|
|
|
|
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
|
|
[btn setBackgroundColor:mainColor];
|
|
|
|
[btn addTarget:self action:@selector(setCodeImg) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
btn.layer.cornerRadius = 3;
|
|
|
|
btn.layer.masksToBounds = YES;
|
|
|
|
[self.view addSubview:btn];
|
|
|
|
[self.view bringSubviewToFront:btn];
|
|
|
|
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.equalTo(self.view).offset(Adapted(15));
|
|
|
|
make.right.equalTo(self.view.mas_right).offset(-Adapted(15));
|
|
|
|
make.bottom.equalTo(self.view.mas_bottom).offset(-Adapted(34));
|
|
|
|
make.height.offset(44);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.editUser getjkCodeSuccess:^(id responseObject) {
|
|
|
|
NSDictionary *dic = (NSDictionary *)responseObject;
|
|
|
|
if ([dic isKindOfClass:NSDictionary.class])
|
|
|
|
{
|
|
|
|
NSString *url = dic[@"url"];
|
|
|
|
if (url.length > 0)
|
|
|
|
{
|
|
|
|
[self.codeBtn sd_setImageWithURL:[NSURL URLWithString:dic[@"url"]] forState:0 placeholderImage:[UIImage imageNamed:@""] options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
|
|
|
self.editUser.image = image;
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(id faiObject) {
|
|
|
|
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark 选择jjm
|
|
|
|
/// 选择jjm
|
|
|
|
- (void)selectCodeImg
|
|
|
|
{
|
|
|
|
UIAlertController *sheet = [myHelper getAlertWithPicture:^(UIImagePickerController *imagePickerVC) {
|
|
|
|
imagePickerVC.delegate = self;
|
|
|
|
[self presentViewController:imagePickerVC animated:YES completion:^{}];
|
|
|
|
}];
|
|
|
|
if(sheet){
|
|
|
|
[self presentViewController:sheet animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark 设置
|
|
|
|
/// 设置
|
|
|
|
- (void)setCodeImg
|
|
|
|
{
|
|
|
|
if (self.editUser.image == nil)
|
|
|
|
{
|
|
|
|
[UICommon MessageErrorText:@"请选择图片"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[UICommon MessageUpload:@"上传中"];
|
|
|
|
[self.editUser updatajkCodeSuccess:^(id responseObject) {
|
|
|
|
[UICommon HidenLoading];
|
|
|
|
[UICommon MessageSuccessText:@"上传成功" isImg:YES];
|
|
|
|
} failure:^(id faiObject) {
|
|
|
|
[UICommon MessageErrorText:@"上传失败"];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark UIImagePickerControllerDelegate
|
|
|
|
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
|
|
|
|
if ([UIDevice currentDevice].systemVersion.floatValue < 11) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ([viewController isKindOfClass:NSClassFromString(@"PUPhotoPickerHostViewController")]) {
|
|
|
|
[viewController.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
|
if (obj.frame.size.width < 42) {
|
|
|
|
[viewController.view sendSubviewToBack:obj];
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
|
|
|
|
{
|
|
|
|
[picker dismissViewControllerAnimated:YES completion:^{}];
|
|
|
|
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
|
|
|
|
self.editUser.image = image;
|
|
|
|
[self.codeBtn setImage:image forState:0];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
|
|
|
|
{
|
|
|
|
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (User *)editUser{
|
|
|
|
if (!_editUser) {
|
|
|
|
_editUser = [[User alloc] init];
|
|
|
|
_editUser.image = cUser.image;
|
|
|
|
}
|
|
|
|
return _editUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
#pragma mark - Navigation
|
|
|
|
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
// Get the new view controller using [segue destinationViewController].
|
|
|
|
// Pass the selected object to the new view controller.
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
@end
|