123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- //
- // YOUPAIMinePhotoCell.m
- // MSYOUPAI
- //
- // Created by admin on 2022/3/2.
- // Copyright © 2022 MS. All rights reserved.
- //
- #import "YOUPAIMineInfoPhotoCell.h"
- #import "UIView+Category.h"
- #import "YOUPAILCUserShowModel.h"
- @implementation YOUPAIMineInfoPhotoCell{
- UILongPressGestureRecognizer *longPress;
- }
- +(CGFloat)itemwidth{
- return (KScreenWidth-24-16)/3;
- }
- +(CGFloat)cellheight{
- return (YOUPAIMineInfoPhotoCell.itemwidth*2)+8+54+69;
- }
- -(UICollectionViewFlowLayout *)flowLayout{
- if (_flowLayout == nil){
- _flowLayout = [UICollectionViewFlowLayout new];
- _flowLayout.minimumLineSpacing = 7;
- _flowLayout.minimumInteritemSpacing = 7;
- CGFloat itemwidth = YOUPAIMineInfoPhotoCell.itemwidth;
- _flowLayout.itemSize = CGSizeMake(itemwidth, itemwidth);
- _flowLayout.sectionInset = UIEdgeInsetsMake(0, 12, 0, 12);
- }
- return _flowLayout;
- }
- -(UICollectionView *)collectionView{
- if (_collectionView == nil){
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.flowLayout];
- _collectionView.backgroundColor = UIColor.clearColor;
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- [_collectionView registerClass:[YOUPAIMinePhotoCollectionViewCell class] forCellWithReuseIdentifier:@"YOUPAIMinePhotoCollectionViewCell"];
- longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(youpaiflongPressHandel:)];
- [self addGestureRecognizer:longPress];
- }
- return _collectionView;
- }
- -(UILabel *)remarkLab{
- if (_remarkLab == nil){
- _remarkLab = [UILabel new];
- _remarkLab.numberOfLines = 2;
- _remarkLab.textColor = LZA3AABEColor;
- _remarkLab.font = LCFont12;
- }
- return _remarkLab;
- }
- -(YOUPAIBubbleLabel *)bubbleLab{
- if (_bubbleLab == nil){
- _bubbleLab = [YOUPAIBubbleLabel new];
- _bubbleLab.text = @"上传照片奖励+20钻石";
- }
- return _bubbleLab;
- }
- -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
- [self.contentView addSubview:self.collectionView];
- [self.contentView addSubview:self.remarkLab];
- [self.contentView addSubview:self.bubbleLab];
-
- [self makeLayout];
- [self defualUI];
- }
- return self;
- }
- -(void)defualUI{
- self.titleLab.text = @"展示照片";
- self.remarkLab.text = @"1、拖拽相片可以更改排序,单击查看大图可删除相册\n2、照片涉黄或者审核不通过将被删除,严重者冻结账号";
- // self.vlaueLab.text = @"去录制";
- }
- -(void)makeLayout{
- [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.mas_equalTo(self.rightArrow);
- make.left.mas_equalTo(12);
- }];
- [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.mas_equalTo(self.mas_top).offset(27);
- make.right.mas_equalTo(-12);
- }];
- [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self).offset(54);
- make.left.right.mas_equalTo(self);
- make.height.mas_equalTo((YOUPAIMineInfoPhotoCell.itemwidth*2) + 8);
- }];
- [_remarkLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(69);
- make.left.mas_equalTo(self.titleLab);
- make.top.mas_equalTo(self.collectionView.mas_bottom);
- }];
- [_bubbleLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.titleLab.mas_right).offset(2);
- make.centerY.mas_equalTo(self.titleLab);
- }];
- [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(0.5);
- make.centerX.mas_equalTo(0);
- make.width.mas_offset(KScreenWidth-30);
- }];
-
- }
- #pragma mark - 拖拽事件照片处理
- - (void)youpaiflongPressHandel:(UILongPressGestureRecognizer*)sender{
-
- if (sender.state == UIGestureRecognizerStateBegan) {
- NSIndexPath *selectIndexPath = [_collectionView indexPathForItemAtPoint:[sender locationInView:_collectionView]];
-
- [_collectionView beginInteractiveMovementForItemAtIndexPath:selectIndexPath];
- }else if (sender.state == UIGestureRecognizerStateChanged){
- [_collectionView updateInteractiveMovementTargetPosition:[sender locationInView:sender.view]];
-
- }else if (sender.state == UIGestureRecognizerStateEnded) {
- [_collectionView endInteractiveMovement];
-
- }else{
- [_collectionView cancelInteractiveMovement];
- }
- }
- // MARK: delegate
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return 6;
- }
- -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- YOUPAIMinePhotoCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAIMinePhotoCollectionViewCell" forIndexPath:indexPath];
- if (indexPath.row < _youpaipimages.count){
- NSString *item = _youpaipimages[indexPath.row];
- NSURL *url = [[LCTools getImageUrlWithAddress:item] urlWithImageScale:60];
- cell.youpaipImageView.contentMode = UIViewContentModeCenter;
- [cell.youpaipImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"icon_180_up_plus"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
- if(error){
- cell.youpaipImageView.contentMode = UIViewContentModeCenter;
- }else{
- cell.youpaipImageView.contentMode = UIViewContentModeScaleAspectFill;
- }
- }];
-
- }else{
- cell.youpaipImageView.contentMode = UIViewContentModeCenter;
- cell.youpaipImageView.image = [UIImage imageNamed:@"icon_180_up_plus"];
- }
- return cell;
- }
- -(BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.row>=_youpaipimages.count){
- return false;
- }
- return true;
- }
- - (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(nonnull NSIndexPath *)sourceIndexPath toIndexPath:(nonnull NSIndexPath *)destinationIndexPath
- {
- @weakify(self);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- @strongify(self);
- if (destinationIndexPath.row>=self.youpaipimages.count){
- [self.collectionView reloadData];
- return;
- }
- if (sourceIndexPath.row>= self.youpaipimages.count){
- [self.collectionView reloadData];
-
- return;
- }
- [self.youpaipimages exchangeObjectAtIndex:sourceIndexPath.item withObjectAtIndex:destinationIndexPath.item];
- [self.collectionView reloadData];
- });
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
-
- if (_delegate && [_delegate respondsToSelector:@selector(mineInfoPhotoCellhandle:indexpath:)]){
- [_delegate mineInfoPhotoCellhandle:self indexpath:indexPath];
- }
- }
- @end
- @implementation YOUPAIMinePhotoCollectionViewCell
- -(UIImageView *)youpaipImageView{
- if (_youpaipImageView == nil){
- _youpaipImageView = [UIImageView new];
- [_youpaipImageView ms_radius:10];
- _youpaipImageView.backgroundColor = LZF7F8FAColor;
- _youpaipImageView.image = [UIImage imageNamed:@"icon_180_up_plus"];
- _youpaipImageView.contentMode = UIViewContentModeCenter;
- }
- return _youpaipImageView;
- }
- -(instancetype)initWithFrame:(CGRect)frame{
- if (self == [super initWithFrame:frame]){
- [self.contentView addSubview:self.youpaipImageView];
- [self makeLayout];
- }
- return self;
- }
- -(void)makeLayout{
- [_youpaipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(0);
- }];
-
- }
- @end
|