// // ProfileCardViewController.m // Youth // // Created by mambaxie on 2022/1/2. // #import "ProfileCardViewController.h" #import "SettingsViewController.h" #import "AvatarView.h" #import "EditProfileViewController.h" #import "UserListViewController.h" #import "MTActionSheet.h" #import "ReportViewController.h" #import "UIImage+TintColor.h" #import "ProfilePhotoCell.h" #import "TZImagePickerController+MTImagePicker.h" #import "KSPhotoBrowser.h" #import "WalletViewController.h" #import "BottleService.h" #import "BigUserImgAlertView.h" @interface ProfileCardViewController () @property (nonatomic, strong) UIView *navBgView; @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, assign) CGFloat scrollAdjustHeight; @property (nonatomic, assign) BOOL isThemeNavStyle; @property (nonatomic, strong) UIView *emptyTipsView; @property (nonatomic, assign) int userID; @property (nonatomic, assign) BOOL isBlack; @property (nonatomic, strong) NSMutableArray *photosM; @property (nonatomic, strong) UIView *headerView; @property (nonatomic, strong) MTActionSheet *moreSheet; @property (nonatomic, strong) MTActionSheet *photoSheet; @property (nonatomic, strong) ProfilePhoto *actionSheetPhoto; @property (nonatomic, strong) KSPhotoBrowser *browser; @end @implementation ProfileCardViewController - (instancetype)initWithUserID:(int)userID { if (self = [super init]) { _userID = userID; } return self; } - (void)setOriginUser:(User *)originUser { _originUser = originUser; self.user = originUser; } - (BOOL)isSelf { return self.userID == [UserService currentUser].ID; } - (BOOL)mt_nagationBarTransparent { return YES; } - (void)setIsThemeNavStyle:(BOOL)isThemeNavStyle { if (_isThemeNavStyle == isThemeNavStyle) { return; } _isThemeNavStyle = isThemeNavStyle; WeakSelf(self); if (isThemeNavStyle) { self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[PYThemeButton navItemWithImageName:@"TH_return_icon_white" action:^(UIButton * _Nonnull button) { [weakself.navigationController popViewControllerAnimated:YES]; }]]; if ([self isSelf]) { // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[PYThemeButton navItemWithImageName:@"setting_icon_white" action:^(UIButton * _Nonnull button) { // [weakself openSettingsVC]; // }]]; } else { self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[PYThemeButton navItemWithImageName:@"TH_pro_more_icon_white" action:^(UIButton * _Nonnull button) { [weakself more]; }]]; } } else { self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:ImageNamed(@"TH_back_black") style:UIBarButtonItemStylePlain target:weakself.navigationController action:@selector(popViewControllerAnimated:)]; if ([self isSelf]) { self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[ImageNamed(@"TH_setting_icon_white") mt_imageWithTintColor:TITLE_COLOR] style:UIBarButtonItemStylePlain target:self action:@selector(openSettingsVC)]; } else { self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:ImageNamed(@"TH_pro_more_icon_black") style:UIBarButtonItemStylePlain target:self action:@selector(more)]; } } } - (void)openSettingsVC { [PYAppService pushViewControllerAnimated:[SettingsViewController new]]; } - (void)viewDidLoad { [super viewDidLoad]; self.isThemeNavStyle = YES; [self startLoading]; [UserService getUserInfoWithUserID:self.userID completion:^(User * _Nonnull user) { self.user = user; [UserService getUserPhotosWithUserID:self.userID completion:^(NSArray * _Nonnull photos) { self.photosM = [photos mutableCopy]; [self endLoading:nil]; [self setupUI]; }]; }]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // [UserService getUserInfoWithUserID:self.userID completion:^(User * _Nonnull user) { // if (user) { // self.user = user; // [self setupUI]; // } // }]; } - (void)setupUI { [self.view removeSubviews]; UIImageView *bgImageView = [[UIImageView alloc] init]; // bgImageView.image = ImageNamed(@"TH_chat_bg"); bgImageView.image = ImageNamed(@"TH_BaseLocalBg"); bgImageView.frame = CGRectMake(0, 0,self.view.width , self.view.height); bgImageView.contentMode = UIViewContentModeScaleAspectFill; [self.view addSubview:bgImageView]; 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:self.view.bounds collectionViewLayout:layout]; self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, homeIndicatorHeight() + FIX_SIZE(10), 0); [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.collectionView reloadData]; // [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"PrifilePhotoSectionHeaderID"]; self.title = nil; // Do any additional setup after loading the view. self.isThemeNavStyle = YES; WeakSelf(self); UIView *headerView = [[UIView alloc] init]; headerView.width = SCREEN_WIDTH; PYImageView *topBgImage = [[PYImageView alloc] init]; [topBgImage sd_setImageWithURL:[NSURL URLWithString:self.user.cover_img?self.user.cover_img:@""] placeholderImage:ImageNamed(@"TH_pro_def_bg")]; topBgImage.width = SCREEN_WIDTH; topBgImage.height = FIX_SIZE(150); [headerView addSubview:topBgImage]; User *user = self.user; AvatarView *avatarView = [AvatarView avatarWithUser:user]; [avatarView addTapGestureTarget:self action:@selector(userImgVAlertClick:)]; avatarView.size = CGSizeMake(FIX_SIZE(84), FIX_SIZE(84)); avatarView.layer.cornerRadius = FIX_SIZE(15); avatarView.y = FIX_SIZE(120); avatarView.x = FIX_SIZE(15); avatarView.user = user; [headerView addSubview:avatarView]; avatarView.userInteractionEnabled = YES; self.scrollAdjustHeight = avatarView.bottom - NAVIGATION_BAR_HEIGHT; self.headerView = headerView; UIView *toolBar = [[UIView alloc] init]; toolBar.height = avatarView.bottom - topBgImage.bottom; toolBar.width = SCREEN_WIDTH - avatarView.right; NSArray *titles = @[@"好友", @"关注数", @"被关注数"]; NSArray *values = @[@(user.friend_count), @(user.user_followed_count), @(user.followed_user_count)]; NSArray *scenes = @[@(UserListSceneFriends), @(UserListSceneFollowing), @(UserListSceneFollowers)]; CGFloat itemWith = toolBar.width / titles.count; for (int i = 0; i < titles.count; i++) { UIView *item = [self itemWithTitle:titles[i] count:[values[i] intValue] width:itemWith]; item.x = item.width * i; [toolBar addSubview:item]; item.centerY = toolBar.height * 0.5; if (self.user.isSelf) { [item addTapWithAction:^{ UserListViewController *userListVC = [[UserListViewController alloc] init]; userListVC.scene = [scenes[i] intValue]; [PYAppService pushViewControllerAnimated:userListVC]; }]; } } [headerView addSubview:toolBar]; toolBar.bottom = avatarView.bottom; toolBar.x = avatarView.right; UILabel *nickNameLabel = [UILabel mt_titleLabelWithText:user.nickname]; nickNameLabel.font = MT_FONT_MEDIUM_SIZE(20); nickNameLabel.x = avatarView.x; nickNameLabel.width = SCREEN_WIDTH - nickNameLabel.x * 2 - FIX_SIZE(18) * 2; nickNameLabel.height = FIX_SIZE(30); nickNameLabel.y = avatarView.bottom + FIX_SIZE(10); nickNameLabel.text = user.nickname; nickNameLabel.numberOfLines = 0; [nickNameLabel sizeToFit]; [headerView addSubview:nickNameLabel]; PYImageView *vipTagView = [[PYImageView alloc] init]; vipTagView.size = CGSizeMake(FIX_SIZE(15), FIX_SIZE(15)); vipTagView.imageUrl = [user vip_flag_img]; vipTagView.x = nickNameLabel.right + FIX_SIZE(6); vipTagView.centerY = nickNameLabel.centerY; [headerView addSubview:vipTagView]; BOOL isVIP = user.isVIP; vipTagView.hidden = !isVIP; nickNameLabel.textColor = isVIP ? THEME_COLOR : UIColor.whiteColor; UIButton *ageButton = [[UIButton alloc] init]; ageButton.titleLabel.font = MT_FONT_REGULAR_SIZE(11); [ageButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [ageButton setTitle:[NSString stringWithFormat:@"%@%@", user.gender_str, user.age.length > 0 ? [NSString stringWithFormat:@" %@", user.age] : @""] forState:UIControlStateNormal]; ageButton.x = nickNameLabel.x; ageButton.y = nickNameLabel.bottom + FIX_SIZE(4); ageButton.titleLabel.font = MT_FONT_REGULAR_SIZE(11); [ageButton sizeToFit]; [headerView addSubview:ageButton]; ageButton.width += 4; ageButton.height = FIX_SIZE(16); [ageButton setTitleColor:[user genderColor] forState:UIControlStateNormal]; ageButton.clipsToBounds = YES; ageButton.layer.cornerRadius = FIX_SIZE(5); ageButton.layer.borderWidth = 0.5; ageButton.backgroundColor = [user genderBGColor]; ageButton.layer.borderColor = ageButton.backgroundColor.CGColor; UILabel *locationLabel = [UILabel mt_titleLabelWithText:user.city.length > 0 ? [NSString stringWithFormat:@"%@·%@", user.province, user.city] : @""]; locationLabel.font = MT_FONT_REGULAR_SIZE(11); locationLabel.textColor = COLOR_WITH_RGB(0xB3B3B3); [locationLabel sizeToFit]; locationLabel.textAlignment = NSTextAlignmentCenter; if (locationLabel.text.length > 0) { locationLabel.x = ageButton.right + FIX_SIZE(6); locationLabel.width += 8; locationLabel.height = ageButton.height; } locationLabel.centerY = ageButton.centerY; locationLabel.backgroundColor = SUB_BG_COLOR; locationLabel.clipsToBounds = YES; locationLabel.layer.cornerRadius = ageButton.layer.cornerRadius; locationLabel.layer.borderWidth = 0.5; locationLabel.layer.borderColor = COLOR_WITH_RGB(0x454358).CGColor; [headerView addSubview:locationLabel]; UIView *line = [UIView lineViewWithWidth:SCREEN_WIDTH - nickNameLabel.x * 2]; line.y = MAX(locationLabel.bottom, ageButton.bottom) + FIX_SIZE(10); [headerView addSubview:line]; UILabel *sloganLabel = [[UILabel alloc] init]; sloganLabel.textColor = COLOR_WITH_RGB(0xB3B3B3); sloganLabel.font = MT_FONT_REGULAR_SIZE(13); sloganLabel.text = user.intro; sloganLabel.width = line.width; sloganLabel.x = line.x; sloganLabel.y = line.bottom + FIX_SIZE(10); sloganLabel.numberOfLines = 0; [sloganLabel sizeToFit]; [headerView addSubview:sloganLabel]; if ([self isSelf]) { PYThemeButton *editButton = [PYThemeButton buttonWithTitle:@"编辑资料" action:^(UIButton * _Nonnull button) { [PYAppService pushViewControllerAnimated:[EditProfileViewController new]]; }]; editButton.height = FIX_SIZE(36); editButton.width = line.width; editButton.titleLabel.font = MT_FONT_MEDIUM_SIZE(13); editButton.layer.cornerRadius = FIX_SIZE(12); [editButton setTitleColor:TITLE_COLOR forState:UIControlStateNormal]; // [editButton setBackgroundColor:COLOR_WITH_RGB(0x383A4A)]; [editButton btnLayerForColor:COLOR_WITH_RGB(0xFFE6D3) toColor:COLOR_WITH_RGB(0xBE7746) andWithCornerRadius:10]; editButton.y = sloganLabel.bottom + FIX_SIZE(15); editButton.centerX = line.centerX; [headerView addSubview:editButton]; } else { if ([self.user isFollowing]) { CGFloat space = FIX_SIZE(9); CGFloat width = (line.width - space) / 2.0; PYThemeButton *leftButton = [PYThemeButton smallButtonWithTitle:self.user.relation == RelationTypeFriends ? @"互相关注" : @"已关注" action:^(UIButton * _Nonnull button) { [MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) { config.title = @"取消关注"; config.message = @"是否确定取消关注?"; config.cancelTitle = @"取消"; config.otherTitle = @"确定"; config.otherHandler = ^(MTAlertButton *button) { [UserService unfollowUserWIthUserID:weakself.user.ID completion:^(id _Nullable rsp, NSError * _Nullable error) { if (!error) { [self.user updateFollowState:NO]; [self.originUser updateFollowState:NO]; [weakself setupUI]; } }]; }; }]; }]; leftButton.titleLabel.font = MT_FONT_MEDIUM_SIZE(13); leftButton.x = line.x; leftButton.width = width; leftButton.height = FIX_SIZE(36); leftButton.y = sloganLabel.bottom + FIX_SIZE(15); // [leftButton setBackgroundColor:COLOR_WITH_RGB(0x383A4A)]; [leftButton btnLayerForColor:COLOR_WITH_RGB(0xFFE6D3) toColor:COLOR_WITH_RGB(0xBE7746) andWithCornerRadius:10]; [leftButton setTitleColor:TITLE_COLOR forState:UIControlStateNormal]; [headerView addSubview:leftButton]; PYThemeButton *rightButton = [PYThemeButton smallButtonWithTitle:@"发消息" action:^(UIButton * _Nonnull button) { [PYAppService chatWithUser:weakself.user]; }]; leftButton.titleLabel.font = rightButton.titleLabel.font; rightButton.frame = leftButton.frame; rightButton.x = leftButton.right + space; [rightButton btnLayerForColor:COLOR_WITH_RGB(0xFFE6D3) toColor:COLOR_WITH_RGB(0xBE7746) andWithCornerRadius:10]; [headerView addSubview:rightButton]; } else { PYThemeButton *followButton = [PYThemeButton buttonWithTitle:@"关注" action:^(UIButton * _Nonnull button) { [UserService followUserWIthUserID:weakself.userID completion:^(id _Nullable rsp, NSError * _Nullable error) { if (!error) { [self.user updateFollowState:YES]; [self.originUser updateFollowState:YES]; [weakself setupUI]; } }]; }]; [followButton setImage:ImageNamed(@"TH_pro_add_icon_white") forState:UIControlStateNormal]; // followButton.height = FIX_SIZE(36); followButton.titleLabel.font = MT_FONT_MEDIUM_SIZE(13); // followButton.width = line.width/2; followButton.layer.cornerRadius = FIX_SIZE(12); [followButton setTitleColor:COLOR_WITH_RGB(0x040000) forState:UIControlStateNormal]; // [followButton setBackgroundColor:THEME_COLOR]; [followButton btnLayerForColor:COLOR_WITH_RGB(0xFFE6D3) toColor:COLOR_WITH_RGB(0xBE7746) andWithCornerRadius:10]; // followButton.y = sloganLabel.bottom + FIX_SIZE(15); // followButton.centerX = line.centerX; // [headerView addSubview:followButton]; CGFloat space = FIX_SIZE(9); CGFloat width = (line.width - space) / 2.0; followButton.titleLabel.font = MT_FONT_MEDIUM_SIZE(13); followButton.x = line.x; followButton.width = width; followButton.height = FIX_SIZE(36); followButton.y = sloganLabel.bottom + FIX_SIZE(15); // [followButton setBackgroundColor:COLOR_WITH_RGB(0x383A4A)]; // [followButton setTitleColor:TITLE_COLOR forState:UIControlStateNormal]; [headerView addSubview:followButton]; PYThemeButton *rightButton = [PYThemeButton smallButtonWithTitle:@"发消息" action:^(UIButton * _Nonnull button) { [PYAppService chatWithUser:weakself.user]; }]; followButton.titleLabel.font = rightButton.titleLabel.font; rightButton.frame = followButton.frame; rightButton.x = followButton.right + space; [rightButton btnLayerForColor:COLOR_WITH_RGB(0xFFE6D3) toColor:COLOR_WITH_RGB(0xBE7746) andWithCornerRadius:10]; [headerView addSubview:rightButton]; } } UILabel *photosTitleView = [[UILabel alloc] init]; photosTitleView.width = SCREEN_WIDTH; photosTitleView.height = FIX_SIZE(50); photosTitleView.text = @"我的形象墙"; photosTitleView.textAlignment = NSTextAlignmentCenter; photosTitleView.font = NORMAL_MEDIUM_FONT; photosTitleView.tintColor = TITLE_COLOR; UIView *photoLine = [UIView lineViewWithWidth:SCREEN_WIDTH]; [photosTitleView addSubview:photoLine]; UIView *tipsBar = [[UIView alloc] init]; tipsBar.width = FIX_SIZE(90); tipsBar.height = 2; tipsBar.backgroundColor = THEME_COLOR; tipsBar.centerX = photosTitleView.width * 0.5; tipsBar.bottom = photosTitleView.height; [photosTitleView addSubview:tipsBar]; photosTitleView.y = headerView.subviews.lastObject.bottom + NORMAL_SPACE; [headerView addSubview:photosTitleView]; 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:self.user.isSelf ? @"上传你的照片\n让别人了解你" : @"Ta还没有生活照片墙"]; 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 = photosTitleView.bottom + FIX_SIZE(3); self.emptyTipsView = emptyTipsView; [headerView addSubview:emptyTipsView]; headerView.width = SCREEN_WIDTH; emptyTipsView.hidden = self.photosM.count > 0; UIView *navBgView = [[UIView alloc] init]; navBgView.height = NAVIGATION_BAR_HEIGHT; navBgView.width = SCREEN_WIDTH; navBgView.backgroundColor = UIColor.whiteColor; [self.view addSubview:navBgView]; navBgView.alpha = 0.0; self.navBgView = navBgView; headerView.height = emptyTipsView.y; PYThemeButton *uploadPhotoButton = [PYThemeButton buttonWithTitle:@"上传我的照片" action:^(UIButton * _Nonnull button) { 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 { [UserService getUserPhotosWithUserID:self.userID completion:^(NSArray * _Nonnull photos) { self.photosM = [photos mutableCopy]; [self.collectionView reloadData]; [SVProgressHUD dismiss]; }]; } }]; }]; [weakself.navigationController presentViewController:picker animated:YES completion:nil]; }]; uploadPhotoButton.bottom = self.view.height - homeIndicatorHeight() - FIX_SIZE(10); [self.view addSubview:uploadPhotoButton]; uploadPhotoButton.hidden = !user.isSelf; headerView.clipsToBounds = NO; headerView.y = -headerView.height; self.collectionView.contentInset = UIEdgeInsetsMake(headerView.height, 0, (uploadPhotoButton.hidden ? 0 : self.view.height - uploadPhotoButton.y) + FIX_SIZE(10), 0); [self.collectionView addSubview:headerView]; } - (BOOL)mt_shouldSetupStateful { return NO; } - (UIView *)itemWithTitle:(NSString *)title count:(NSInteger)count width:(CGFloat)width { UIView *item = [[UIView alloc] init]; item.width = width; UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.text = title; titleLabel.textColor = COLOR_WITH_RGB(0xB3B3B3); titleLabel.font = MT_FONT_REGULAR_SIZE(11); [titleLabel sizeToFit]; titleLabel.centerX = width * 0.5; [item addSubview:titleLabel]; UILabel *countLabel = [[UILabel alloc] init]; countLabel.width = width; countLabel.height = FIX_SIZE(25); countLabel.textColor = TITLE_COLOR; countLabel.font = MT_FONT_MEDIUM_SIZE(16); countLabel.y = titleLabel.bottom + FIX_SIZE(3.5); countLabel.text = self.user.is_mask_relation ? @"***" : @(count).stringValue; countLabel.textAlignment = NSTextAlignmentCenter; [item addSubview:countLabel]; item.height = countLabel.bottom; return item; } - (void)more { [UserService getUserBlackWithUserID:self.user.ID completion:^(BOOL isBlack) { self.isBlack = isBlack; MTActionSheet *sheet = nil; if ([UserService currentUser].is_manager > 0) { sheet = [[MTActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"聊天", isBlack ? @"移出黑名单" : @"加入黑名单", @"举报", @"处理此账户", nil]; }else{ sheet = [[MTActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"聊天", isBlack ? @"移出黑名单" : @"加入黑名单", @"举报", nil]; } [sheet showInView:self.view.window]; self.moreSheet = sheet; }]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { // CGFloat alpha = scrollView.contentOffset.y / self.scrollAdjustHeight; // alpha = MIN(1, alpha); // alpha = MAX(0, alpha); // self.navBgView.alpha = alpha; // self.isThemeNavStyle = alpha < 1.0; } #pragma mark - MTActionSheetDelegate - (void)actionSheet:(MTActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { if (self.moreSheet == actionSheet) { switch (buttonIndex) { case 0: // 聊天 { [PYAppService chatWithUser:self.user]; break; } case 1: // 拉黑 { [UserService setUserBlackWithUserID:self.user.ID isBlack:!self.isBlack completion:^(id _Nullable rsp, NSError * _Nullable error) { if (!error) { if (self.isBlack) { [SVProgressHUD showSuccessWithStatus:@"取消拉黑成功"]; } else { [SVProgressHUD showSuccessWithStatus:@"拉黑成功"]; } } }]; break; } case 2: // 举报 { ReportViewController *vc = [[ReportViewController alloc] init]; vc.user = self.user; [PYAppService pushViewControllerAnimated:vc]; break; } case 3: // 管理员 { [UserService dealUser:self.user.ID]; break; } default: break; } return; } if (self.photoSheet == actionSheet) { if (buttonIndex == 0) { // 置顶 BOOL isTop = !self.actionSheetPhoto.is_top; [UserService topUserPhotoWithImageURL:self.actionSheetPhoto.url isTop:isTop completion:^(id _Nullable rsp, NSError * _Nullable error) { if (!error) { if (isTop) { [ToastUtil showToast:@"置顶成功"]; //把这个图片置顶显示 [self.photosM removeObject:self.actionSheetPhoto]; [self.photosM insertObject:self.actionSheetPhoto atIndex:0]; } else { //把这个图片从置顶里移到非置顶第一个 [ToastUtil showToast:@"已取消置顶"]; for (int i = 0; i < self.photosM.count; i++) { if (!self.photosM[i].is_top || i == self.photosM.count - 1) { [self.photosM removeObject:self.actionSheetPhoto]; [self.photosM insertObject:self.actionSheetPhoto atIndex:i]; break; } } } self.actionSheetPhoto.is_top = isTop; [self.collectionView reloadData]; }else{ [ToastUtil showToast:error.userInfo[@"message"]]; } }]; } else if (buttonIndex == 1) { // 删除 [MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) { config.title = @"确定删除?"; config.cancelTitle = @"否"; config.otherTitle = @"是"; config.otherHandler = ^(MTAlertButton *button) { [UserService deleteUserPhotoWithImageURL:self.actionSheetPhoto.url completion:^(id _Nullable rsp, NSError * _Nullable error) { if (!error) { [SVProgressHUD showSuccessWithStatus:@"删除成功"]; [self.browser deleteImageForIndex:[self.photosM indexOfObject:self.actionSheetPhoto]]; [self.photosM removeObject:self.actionSheetPhoto]; [self.collectionView reloadData]; } }]; }; }]; } } } #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++) { if ([self.photosM[i].url containsString:@".wep"]) { KSPhotoItem *item = [KSPhotoItem itemWithSourceView:cell.imageView image:cell.imageView.image]; } else { 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 (!self.user.isSelf && ![UserService currentUser].is_manager) { // 查看别人照片点击无反应 return; } 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; } -(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]; } @end