// // MineViewController.m // TreeHole // // Created by 郑创权 on 2022/11/13. // #import "MineViewController.h" #import "BigUserImgAlertView.h" #import "ProfileCardViewController.h" //个人页面 #import "UserListViewController.h" //列表 #import "AlertInputView.h" #import "InviteCodeViewController.h"//邀请页面 #import "SettingsViewController.h"//设置页面 #import "FeedbackViewController.h"//意见反馈 #import "TZImagePickerController+MTImagePicker.h" #import "THMineHeaderView.h" #import "THMineTypeNavView.h" #import "ProfilePhotoCell.h" #import "MTActionSheet.h" #import "VIPCardInfo.h" static NSString * const DidActionScoreKey = @"DidActionScoreKey"; static NSString * const DidActionFollowPublicAccountKey = @"DidActionFollowPublicAccountKey"; @interface MineViewController () @property (nonatomic, strong)User* userModel;//个人信息 @property (nonatomic, strong)UIView* userView; @property (nonatomic, strong)UIView* nianVipView; @property (nonatomic, strong)UILabel* nianVipLab; @property (nonatomic, strong) UIView *emptyTipsView; @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, strong)UIButton* openVipBtn; @property (nonatomic, strong)UILabel* openVipLab; @property (nonatomic, strong)UIView* contentTableView; @property (nonatomic,strong) NSMutableArray *infoArray; @property (nonatomic, strong) NSMutableArray *photosM; @property (nonatomic, strong) MTActionSheet *moreSheet; @property (nonatomic, strong) MTActionSheet *photoSheet; @property (nonatomic, strong) ProfilePhoto *actionSheetPhoto; @property (nonatomic, strong) KSPhotoBrowser *browser; @end @implementation MineViewController -(NSMutableArray *)infoArray { if (!_infoArray) { _infoArray = [NSMutableArray array]; } return _infoArray; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; if (_userModel.isVIP) { [_openVipBtn setBackgroundImage:[UIImage imageNamed:@"TH_pro_vip_card_content_S"] forState:UIControlStateNormal]; _nianVipView.hidden = NO; _openVipLab.hidden = NO; if([UserService currentUser].vip_kind == 10){ _nianVipLab.text = @"年VIP"; }else{ _nianVipLab.text = @"VIP"; } }else{ _nianVipView.hidden = YES; } [UserService getUserInfoWithCompletion:^(User * _Nonnull user) { [self getNoticeCount]; [self loadPhotosData]; [self refreshVIPInfo]; }]; self.navigationController.navigationBar.hidden = true; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.navigationController.navigationBar.hidden = false; } - (void)refreshVIPInfo { [PYHTTPManager postWithPath:@"myvipcard" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) { VIPCardInfo *info = [VIPCardInfo mj_objectWithKeyValues:rsp]; if (info.vipcard.vip_exp_date.length > 0) { self.openVipLab.text = info.vipcard.vip_exp_date; } }]; } - (void)loadPhotosData { [UserService getUserPhotosWithUserID:[UserService currentUserID] completion:^(NSArray * _Nonnull photos) { self.photosM = [photos mutableCopy]; if (self.photosM.count == 0) { self.emptyTipsView.hidden = false; self.collectionView.hidden = true; self.contentScrollView.contentSize = CGSizeMake(SCREEN_WIDTH,TAB_BAR_HEIGHT + self.emptyTipsView.qmui_bottom + 30); } else { self.emptyTipsView.hidden = true; self.collectionView.hidden = false; self.contentScrollView.contentSize = CGSizeMake(SCREEN_WIDTH,TAB_BAR_HEIGHT + self.collectionView.qmui_bottom); [self.collectionView reloadData]; } }]; } - (void)upLoadAction { if(self.photosM.count >= 9){ [SVProgressHUD showErrorWithStatus:@"为了让形象照质量更高,目前只允许上传9张~"]; return; } TZImagePickerController *picker = [TZImagePickerController mt_imagePickerWithMaxImagesCount:9 - self.photosM.count didFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { dispatch_async(dispatch_get_main_queue(), ^{ [SVProgressHUD showWithStatus:nil]; }); [UserService uploadUserPhotoWithImages:photos completion:^(id _Nullable rsp, NSError * _Nullable error) { if (error) { [SVProgressHUD showErrorWithStatus:@"上传失败,请稍后重试"]; } else { [SVProgressHUD dismiss]; [self loadPhotosData]; } }]; }]; [self.navigationController presentViewController:picker animated:YES completion:nil]; } -(void)getNoticeCount { _userModel = [UserService currentUser]; for (UIView *view in self.contentScrollView.subviews) { [view removeFromSuperview]; } _userView= [[UIView alloc]initWithFrame:CGRectMake(0, STATUS_BAR_HEIGHT + FIX_SIZE(12), SCREEN_WIDTH, FIX_SIZE(212))]; [self.contentScrollView addSubview:self.userView]; NSArray * xibArray = [[NSBundle mainBundle]loadNibNamed:NSStringFromClass(THMineHeaderView.class) owner:nil options:nil] ; THMineHeaderView *headerView = xibArray.firstObject; headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 30); [_userView addSubview:headerView]; UIImageView* userImgV = [[UIImageView alloc]initWithFrame:CGRectMake(FIX_SIZE(20), FIX_SIZE(40), FIX_SIZE(68), FIX_SIZE(68))]; userImgV.contentMode = UIViewContentModeScaleToFill; userImgV.layer.cornerRadius = userImgV.width/2.0; userImgV.layer.masksToBounds = YES; userImgV.tag = 800001; [userImgV sd_setImageWithURL:[NSURL URLWithString:_userModel.avatar] placeholderImage:[UIImage imageNamed:@"TH_defalut_avatar"]]; userImgV.userInteractionEnabled = YES; [userImgV addTapGestureTarget:self action:@selector(userImgVAlertClick:)]; [_userView addSubview:userImgV]; UILabel* userNameLab = [[UILabel alloc]initWithFrame:CGRectMake(userImgV.right + FIX_SIZE(15), userImgV.y + FIX_SIZE(6), FIX_SIZE(120), FIX_SIZE(20))]; userNameLab.text = _userModel.nickname; userNameLab.textAlignment = NSTextAlignmentLeft; userNameLab.font = MT_FONT_MEDIUM_SIZE(16); userNameLab.textColor = HEX_COLOR(0xFFFFFF); [_userView addSubview:userNameLab]; UIImageView* userSexImgv = [[UIImageView alloc]initWithFrame:CGRectMake(userNameLab.left, userNameLab.bottom + FIX_SIZE(16), FIX_SIZE(26), FIX_SIZE(16))]; if([_userModel.gender_str isEqualToString:@"CD"]){ userSexImgv.image = [UIImage imageNamed:@"TH_cd_tag"]; }else if([_userModel.gender_str isEqualToString:@"TS"]){ userSexImgv.image = [UIImage imageNamed:@"TH_ts_tag"]; }else{ userSexImgv.image = [UIImage imageNamed:@"TH_zn_tag"]; } userSexImgv.contentMode = UIViewContentModeScaleToFill; [_userView addSubview:userSexImgv]; if (_userModel.isVIP) { userNameLab.textColor = COLOR_WITH_RGB(0xF8D07D); // UIImageView* vipImgV = [[UIImageView alloc]initWithFrame:CGRectMake(userSexImgv.right + FIX_SIZE(5), userSexImgv.y, FIX_SIZE(16), FIX_SIZE(16))]; // vipImgV.image = [UIImage imageNamed:@"vip_tag"]; // vipImgV.contentMode = UIViewContentModeScaleToFill; // [_userView addSubview:vipImgV]; UIView* nianVipView = [[UIView alloc]initWithFrame:CGRectMake(userSexImgv.right + FIX_SIZE(5), userSexImgv.y + (userSexImgv.height - FIX_SIZE(16))/2.0, 34, FIX_SIZE(16))]; nianVipView.layer.cornerRadius = 8; nianVipView.layer.masksToBounds = YES; // gradient CAGradientLayer *gl = [CAGradientLayer layer]; gl.frame = CGRectMake(0,0,nianVipView.width,nianVipView.height); gl.startPoint = CGPointMake(0, 0.5); gl.endPoint = CGPointMake(1, 0.5); gl.colors = @[(__bridge id)HEX_COLOR(0xE4B18B).CGColor, (__bridge id)HEX_COLOR(0xFFF4EC).CGColor, (__bridge id)HEX_COLOR(0xE4B18B).CGColor]; gl.locations = @[@(0), @(0.5f), @(1.0f)]; [nianVipView.layer addSublayer:gl]; UILabel* nianVipLab = [[UILabel alloc]initWithFrame:nianVipView.bounds]; if([UserService currentUser].vip_kind == 10){ nianVipLab.text = @"年VIP"; }else{ nianVipLab.text = @"VIP"; } nianVipLab.textColor = HEX_COLOR(0x000000); nianVipLab.textAlignment = NSTextAlignmentCenter; nianVipLab.font = MT_FONT_MEDIUM_SIZE(10); [nianVipView addSubview:nianVipLab]; // [nianVipLab bringSubviewToFront:nianVipLab.text]; [_userView addSubview:nianVipView]; _nianVipView = nianVipView; _nianVipLab = nianVipLab; }else{ userNameLab.textColor = COLOR_WITH_RGB_A(0xFFFFFF, 0.9); } UIButton* pushPersonalPageBtn = [[UIButton alloc]initWithFrame:CGRectMake(_userView.width - FIX_SIZE(70) - FIX_SIZE(12), userNameLab.y + FIX_SIZE(12), FIX_SIZE(70), FIX_SIZE(24))]; [pushPersonalPageBtn addTarget:self action:@selector(pushPersonalPageBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [_userView addSubview:pushPersonalPageBtn]; UILabel* pushPersonalPageBtnTitleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, FIX_SIZE(54), FIX_SIZE(24))]; pushPersonalPageBtnTitleLab.text = @"进入主页"; pushPersonalPageBtnTitleLab.textAlignment = NSTextAlignmentLeft; pushPersonalPageBtnTitleLab.font = MT_FONT_MEDIUM_SIZE(12); pushPersonalPageBtnTitleLab.textColor = HEX_COLOR(0xFFFFFF); [pushPersonalPageBtn addSubview:pushPersonalPageBtnTitleLab]; UIImageView* pushPersonRightArrowImgV = [[UIImageView alloc]initWithFrame:CGRectMake(pushPersonalPageBtnTitleLab.right , 0, FIX_SIZE(24), FIX_SIZE(24))]; pushPersonRightArrowImgV.image = [UIImage imageNamed:@"TH_pro_right_arrow_white"]; pushPersonRightArrowImgV.contentMode = UIViewContentModeScaleToFill; [pushPersonalPageBtn addSubview:pushPersonRightArrowImgV]; NSLog(@"getNoticeCount==%@",self.infoArray); //互关,关注,粉丝 // userModel.friend_count // add_friend_count // add_user_followed_count // add_followed_user_count NSArray* functionArray = @[@{@"num":@(_userModel.friend_count),@"title":@"互关"}, @{@"num":@(_userModel.user_followed_count),@"title":@"关注"}, @{@"num":@(_userModel.followed_user_count),@"title":@"粉丝"}]; UIView* functionView = [[UIView alloc]initWithFrame:CGRectMake(0, userImgV.bottom, SCREEN_WIDTH, _userView.height - userImgV.bottom)]; // functionView.backgroundColor = [UIColor whiteColor]; [_userView addSubview:functionView]; CGFloat functionBtnW = FIX_SIZE(120); CGFloat functionBtnH = functionView.height; CGFloat functionBtnJianGe = (SCREEN_WIDTH - FIX_SIZE(40) - functionBtnW*functionArray.count)/(functionArray.count-1); for (NSInteger i = 0 ; i < functionArray.count; i++) { UIButton* functionBtn = [[UIButton alloc]initWithFrame:CGRectMake(FIX_SIZE(20) + (functionBtnJianGe + functionBtnW)*i, 0, functionBtnW, functionBtnH)]; [functionBtn setTitle:functionArray[i][@"title"] forState:UIControlStateNormal]; [functionBtn setTitleColor:HEX_COLOR_A(0x000000, 0) forState:UIControlStateNormal]; [functionBtn addTarget:self action:@selector(functionBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [functionView addSubview:functionBtn]; UILabel* functionBtnNumLab = [[UILabel alloc]initWithFrame:CGRectMake(-2, FIX_SIZE(26), functionBtn.width-3, FIX_SIZE(20))]; functionBtnNumLab.text = [NSString stringWithFormat:@"%@",functionArray[i][@"num"]]; functionBtnNumLab.textAlignment = NSTextAlignmentCenter; functionBtnNumLab.font = MT_FONT_MEDIUM_SIZE(18); functionBtnNumLab.textColor = HEX_COLOR_A(0xFFFFFF, 0.7); functionBtnNumLab.textAlignment = NSTextAlignmentCenter; [functionBtn addSubview:functionBtnNumLab]; UILabel*NumLab = [[UILabel alloc]initWithFrame:CGRectMake(functionBtn.frame.size.width-FIX_SIZE(55), FIX_SIZE(26), 26, FIX_SIZE(20))]; NumLab.textAlignment = NSTextAlignmentRight; NumLab.font = MT_FONT_MEDIUM_SIZE(14); NumLab.textColor = HEX_COLOR_A(0xFFFFFF, 0.7); NumLab.textAlignment = NSTextAlignmentCenter; [functionBtn addSubview:NumLab]; NumLab.backgroundColor = [UIColor redColor]; NumLab.layer.cornerRadius = FIX_SIZE(10); NumLab.layer.masksToBounds = YES; NSLog(@"_userModel.new_friend_count==%d",_userModel .new_friend_count); if (i==0) { if (_userModel.new_friend_count>=99) { NumLab.text = @"99+"; }else{ if (_userModel.new_friend_count==0) { NumLab.hidden = YES; }else{ NumLab.text = [NSString stringWithFormat:@"%d",_userModel.new_friend_count]; } } }else if (i==1) { if (_userModel.new_followed_user_count>=99) { NumLab.text = @"99+"; }else{ if (_userModel.new_followed_user_count==0) { NumLab.hidden = YES; }else{ NumLab.text = [NSString stringWithFormat:@"%d",_userModel.new_followed_user_count]; } } }else{ if (_userModel.new_user_followed_count>=99) { NumLab.text = @"99+"; }else{ if (_userModel.new_user_followed_count==0) { NumLab.hidden = YES; }else{ NumLab.text = [NSString stringWithFormat:@"%d",_userModel.new_user_followed_count]; } } } // [NumLab sizeToFit]; UILabel* functionBtnTitleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, functionBtnNumLab.bottom + FIX_SIZE(9), functionBtn.width, FIX_SIZE(26))]; functionBtnTitleLab.text = functionArray[i][@"title"]; functionBtnTitleLab.textAlignment = NSTextAlignmentCenter; functionBtnTitleLab.font = MT_FONT_MEDIUM_SIZE(18); functionBtnTitleLab.textColor = HEX_COLOR_A(0xFFFFFF, 0.7); [functionBtn addSubview:functionBtnTitleLab]; } [self.contentScrollView addSubview:self.openVipBtn]; NSArray * newxibArray = [[NSBundle mainBundle]loadNibNamed:NSStringFromClass(THMineTypeNavView.class) owner:nil options:nil] ; THMineTypeNavView *navView = newxibArray.firstObject; navView.frame = CGRectMake(0, self.openVipBtn.qmui_bottom + 20,SCREEN_WIDTH, 40); [navView.upBtn addTarget:self action:@selector(upLoadAction) forControlEvents:UIControlEventTouchUpInside]; [self.contentScrollView addSubview:navView]; UIView *emptyTipsView = [[UIView alloc] init]; emptyTipsView.backgroundColor = [UIColor clearColor]; emptyTipsView.width = SCREEN_WIDTH; UIImageView *emptyIconView = [[UIImageView alloc] initWithImage:ImageNamed(@"TH_pro_photo_icon")]; emptyIconView.size = CGSizeMake(FIX_SIZE(49), FIX_SIZE(49)); emptyIconView.centerX = emptyTipsView.width * 0.5; emptyIconView.y = FIX_SIZE(30); [emptyTipsView addSubview:emptyIconView]; UILabel *emptyTipsLabel = [UILabel mt_titleLabelWithText:@"上传你的照片\n让别人了解你"]; emptyTipsLabel.font = NORMAL_FONT; [emptyTipsLabel sizeToFit]; emptyTipsLabel.centerX = emptyIconView.centerX; emptyTipsLabel.y = emptyIconView.bottom + FIX_SIZE(6); [emptyTipsView addSubview:emptyTipsLabel]; emptyTipsView.height = emptyTipsLabel.bottom; emptyTipsView.y = navView.bottom + FIX_SIZE(3); self.emptyTipsView = emptyTipsView; [self.contentScrollView addSubview:self.emptyTipsView]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 1; layout.minimumInteritemSpacing = 1; CGFloat itemWidth = (self.view.width - 3) / 3.0; CGFloat itemHeight = itemWidth * 165.0 / 125.0; layout.itemSize = CGSizeMake(itemWidth, itemHeight); self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, navView.qmui_bottom + 10, SCREEN_WIDTH, 170 * 3) collectionViewLayout:layout]; [self.collectionView registerClass:ProfilePhotoCell.class forCellWithReuseIdentifier:ProfilePhotoCellID]; [self.view addSubview:self.collectionView]; self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; self.collectionView.alwaysBounceVertical = YES; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.backgroundColor = [UIColor clearColor]; [self.contentScrollView addSubview:self.collectionView]; // [self.contentScrollView addSubview:self.contentTableView]; // self.contentScrollView.contentSize = CGSizeMake(SCREEN_WIDTH,TAB_BAR_HEIGHT + self.collectionView.qmui_bottom); } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSLog(@"self.infoArray==%@",self.infoArray); UIImageView *bgImgView = [UIImageView new]; bgImgView.frame = self.view.bounds; bgImgView.image = UIImageMake(@"TH_MineBg"); [self.view insertSubview:bgImgView atIndex:0]; } - (BOOL)isSupportContentScrollView { return YES; } - (BOOL)mt_nagationBarTransparent{ return YES; } //-(UIView *)userView{ // if (!_userView) { // // } // return _userView; //} -(UIButton *)openVipBtn{ if (!_openVipBtn) { _openVipBtn = [[UIButton alloc]initWithFrame:CGRectMake(FIX_SIZE(22), _userView.bottom, SCREEN_WIDTH - FIX_SIZE(44), 339)]; _openVipLab = [[UILabel alloc]initWithFrame:CGRectMake(FIX_SIZE(80), FIX_SIZE(40), FIX_SIZE(160), FIX_SIZE(17))]; _openVipLab.textColor = HEX_COLOR(0xFFFFFF); _openVipLab.font = FONT_SIZE(12); [_openVipBtn addSubview:_openVipLab]; _openVipLab.text = @"二十种专属特权等你领取"; } if (_userModel.isVIP) { [_openVipBtn setBackgroundImage:[UIImage imageNamed:@"TH_pro_vip_card_content_S"] forState:UIControlStateNormal]; _openVipLab.hidden = NO; }else{ [_openVipBtn setBackgroundImage:[UIImage imageNamed:@"TH_pro_vip_card_content_N"] forState:UIControlStateNormal]; // _openVipLab.hidden = YES; } [_openVipBtn addTarget:self action:@selector(openVipBtnClick:) forControlEvents:UIControlEventTouchUpInside]; return _openVipBtn; } -(UIView *)contentTableView{ if (!_contentTableView) { NSArray* dataArray = @[@{@"img":@"TH_pro_yqyj",@"title":@"邀请有奖",@"subTitle":@"免费领取会员",@"isHaveSwitch":@"NO"},@{@"img":@"TH_pro_wdpz",@"title":@"我的瓶子",@"subTitle":@"",@"isHaveSwitch":@"NO"},@{@"img":@"TH_pro_mms",@"title":@"APP密码锁",@"subTitle":@"",@"isHaveSwitch":@"YES"},@{@"img":@"TH_pro_yjfk",@"title":@"意见反馈",@"subTitle":@"有事就找我哈",@"isHaveSwitch":@"NO"},@{@"img":@"TH_pro_gd",@"title":@"更多",@"subTitle":@"",@"isHaveSwitch":@"NO"}]; CGFloat cellH = FIX_SIZE(44); _contentTableView = [[UIView alloc]initWithFrame:CGRectMake(FIX_SIZE(12), _openVipBtn.bottom + FIX_SIZE(25), SCREEN_WIDTH - FIX_SIZE(24) , dataArray.count*cellH + FIX_SIZE(20))]; _contentTableView.layer.cornerRadius = FIX_SIZE(6); _contentTableView.layer.masksToBounds = YES; _contentTableView.layer.borderColor = HEX_COLOR_A(0xFFFFFF, 0.3).CGColor; _contentTableView.layer.borderWidth = FIX_SIZE(1); for (NSInteger i = 0; i < dataArray.count ; i++) { UIButton* cellBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, FIX_SIZE(10) + cellH*i, _contentTableView.width, cellH)]; [cellBtn setTitle:dataArray[i][@"title"] forState:UIControlStateNormal]; [cellBtn setTitleColor:HEX_COLOR_A(0x000000, 0) forState:UIControlStateNormal]; [cellBtn addTarget:self action:@selector(cellBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [_contentTableView addSubview:cellBtn]; UIImageView* iconImgV = [[UIImageView alloc]initWithFrame:CGRectMake(FIX_SIZE(10), (cellBtn.height - FIX_SIZE(24))/2.0, FIX_SIZE(24), FIX_SIZE(24))]; iconImgV.image = [UIImage imageNamed:dataArray[i][@"img"]]; [cellBtn addSubview:iconImgV]; UILabel* leftCellBtnLab = [[UILabel alloc]initWithFrame:CGRectMake(iconImgV.right + FIX_SIZE(10), iconImgV.y, FIX_SIZE(120), FIX_SIZE(24))]; leftCellBtnLab.text = [NSString stringWithFormat:@"%@",dataArray[i][@"title"]]; leftCellBtnLab.textAlignment = NSTextAlignmentLeft; leftCellBtnLab.font = MT_FONT_MEDIUM_SIZE(16); leftCellBtnLab.textColor = HEX_COLOR_A(0xFFFFFF, 1); [cellBtn addSubview:leftCellBtnLab]; UILabel* rightSubCellBtnLab = [[UILabel alloc]initWithFrame:CGRectMake(cellBtn.width - FIX_SIZE(37) - FIX_SIZE(120), iconImgV.y, FIX_SIZE(120), FIX_SIZE(24))]; rightSubCellBtnLab.text = [NSString stringWithFormat:@"%@",dataArray[i][@"subTitle"]]; rightSubCellBtnLab.textAlignment = NSTextAlignmentRight; rightSubCellBtnLab.font = MT_FONT_MEDIUM_SIZE(12); rightSubCellBtnLab.textColor = HEX_COLOR_A(0xFFFFFF, 1); [cellBtn addSubview:rightSubCellBtnLab]; if ([dataArray[i][@"isHaveSwitch"] isEqualToString:@"NO"]) { UIImageView* rightArrowImgV = [[UIImageView alloc]initWithFrame:CGRectMake(cellBtn.width - FIX_SIZE(10) - FIX_SIZE(24), (cellBtn.height - FIX_SIZE(24))/2.0, FIX_SIZE(24), FIX_SIZE(24))]; rightArrowImgV.image = [UIImage imageNamed:@"TH_pro_right_arrow_white"]; [cellBtn addSubview:rightArrowImgV]; }else{ UISwitch* onSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(cellBtn.width - FIX_SIZE(10) - 51, (cellBtn.height - 31)/2.0, 51, 31)]; onSwitch.onTintColor = HEX_COLOR(0xFFAD10); BOOL canOpen = [UserService isSecurityCodeOpen]; onSwitch.on = canOpen; [onSwitch addTarget:self action:@selector(onSwitchClick:) forControlEvents:UIControlEventValueChanged]; [cellBtn addSubview:onSwitch]; } } } return _contentTableView; } //pro_vip_card_content_N //进入个人主页 -(void)pushPersonalPageBtnClick:(UIButton*)sender{ [PYAppService pushViewControllerAnimated:[[ProfileCardViewController alloc] initWithUserID:[UserService currentUserID]]]; } //关注,粉丝,互关 -(void)functionBtnClick:(UIButton*)sender{ UserListViewController *userListVC = [[UserListViewController alloc] init]; if ([sender.titleLabel.text isEqualToString:@"互关"]) { userListVC.scene = 0; }else if ([sender.titleLabel.text isEqualToString:@"关注"]) { userListVC.scene = 1; }else if ([sender.titleLabel.text isEqualToString:@"粉丝"]) { userListVC.scene = 2; } [PYAppService pushViewControllerAnimated:userListVC]; } //vip页面 -(void)openVipBtnClick:(UIButton*)sender{ [PYAppService showVipVC:@"vip_page"]; } //邀请,我的瓶子 -(void)cellBtnClick:(UIButton*)sender{ if ([sender.titleLabel.text isEqualToString:@"邀请有奖"]) { [PYAppService pushViewControllerAnimated:[InviteCodeViewController new]]; }else if ([sender.titleLabel.text isEqualToString:@"我的瓶子"]) { [SVProgressHUD showImage:nil status:@"已放之瓶无须念,往事随风自然开~"]; }else if ([sender.titleLabel.text isEqualToString:@"APP密码锁"]) { }else if ([sender.titleLabel.text isEqualToString:@"意见反馈"]) { [PYAppService pushViewControllerAnimated:[FeedbackViewController new]]; }else if ([sender.titleLabel.text isEqualToString:@"更多"]) { [PYAppService pushViewControllerAnimated:[SettingsViewController new]]; } } -(void)onSwitchClick:(UISwitch*)sender{ if (sender.isOn) { if ([UserService currentUser].security_code.length != SecurityCodeLength) { [sender setOn:NO animated:NO]; [AlertInputView showWithTitle:@"设置密码" content:nil maxLength:SecurityCodeLength action:^BOOL(NSString * _Nonnull content) { if (content.length != SecurityCodeLength) { [ToastUtil showToast:[NSString stringWithFormat:@"请输入%lu位数字", (unsigned long)SecurityCodeLength] position:CSToastPositionTop]; return NO; } [UserService updateUserSecurityToRemote:@{ @"security_code" : content ?: @"", @"is_security_on" : @(1), } completion:^(id _Nullable rsp, NSError * _Nullable error) { if (error) { [sender setOn:NO animated:YES]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]]; }); return; } else { // 设置成功 [sender setOn:YES animated:YES]; [UserService currentUser].security_code = content; [UserService currentUser].is_security_on = 1; } }]; return YES; }]; return; }else{ [sender setOn:NO animated:NO]; [UserService updateUserSecurityToRemote:@{ @"security_code" : [UserService currentUser].security_code, @"is_security_on" : @(1), } completion:^(id _Nullable rsp, NSError * _Nullable error) { if (error) { [sender setOn:NO animated:YES]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]]; }); return; } else { // 设置成功 [UserService currentUser].is_security_on = 1; [sender setOn:YES animated:YES]; } }]; } } else { [UserService updateUserSecurityToRemote:@{ @"security_code" : [UserService currentUser].security_code, @"is_security_on" : @(0), } completion:^(id _Nullable rsp, NSError * _Nullable error) { if (error) { [sender setOn:YES animated:YES]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [SVProgressHUD showErrorWithStatus:[error.userInfo objectForKey:@"message"]]; }); return; } else { // 设置成功 [UserService currentUser].is_security_on = 0; [sender setOn:NO animated:YES]; } }]; } } -(void)userImgVAlertClick:(UITapGestureRecognizer*)tap{ UIImageView* userImgV = (UIImageView*)tap.view; BigUserImgAlertView* alertView = [[BigUserImgAlertView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; alertView.userImg = userImgV.image; [[ZcqVender theTopviewControler].view addSubview:alertView]; } #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { self.emptyTipsView.hidden = self.photosM.count > 0; return self.photosM.count; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { ProfilePhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ProfilePhotoCellID forIndexPath:indexPath]; cell.photo = self.photosM[indexPath.item]; return cell; } #pragma mark - UICollectionDelegate - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { ProfilePhotoCell *cell = (ProfilePhotoCell *)[collectionView cellForItemAtIndexPath:indexPath]; NSMutableArray *items = @[].mutableCopy; for (int i = 0; i < self.photosM.count; i++) { KSPhotoItem *item = [KSPhotoItem itemWithSourceView:indexPath.item == i ? cell.imageView : nil imageUrl:[NSURL URLWithString:self.photosM[i].url ?: @""]]; [items addObject:item]; } KSPhotoBrowser *browser = [KSPhotoBrowser browserWithPhotoItems:items selectedIndex:indexPath.item]; browser.delegate = self; browser.pageindicatorStyle = KSPhotoBrowserPageIndicatorStyleText; browser.backgroundStyle = KSPhotoBrowserBackgroundStyleBlack; [KSPhotoBrowser setImageViewBackgroundColor:[UIColor clearColor]]; browser.dismissalStyle = KSPhotoBrowserInteractiveDismissalStyleScale; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:browser]; self.browser = browser; nav.modalPresentationStyle = UIModalPresentationOverFullScreen; [self.navigationController presentViewController:nav animated:NO completion:nil]; } #pragma mark -KSPhotoBrowserDelegate - (void)ks_photoBrowser:(KSPhotoBrowser *)browser didLongPressItem:(KSPhotoItem *)item atIndex:(NSUInteger)index { if (index < self.photosM.count) { ProfilePhoto *photo = self.photosM[index]; self.actionSheetPhoto = photo; if (photo.is_top) { self.photoSheet = [[MTActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"取消置顶", @"删除", nil]; } else { self.photoSheet = [[MTActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"置顶", @"删除", nil]; } [self.photoSheet showInView:browser.navigationController.view]; } } - (void)ks_photoBrowserDidDismiss:(KSPhotoBrowser *)browser { self.browser = nil; } @end