//MHBeautyView.m //美颜页面 #import "MHBeautyView.h" #import "MHBeautyMenuCell.h" #import "MHBeautyParams.h" #import "MHBeautiesModel.h" @interface MHBeautyView () @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, strong) NSMutableArray *array; @property (nonatomic, assign) NSInteger lastIndex; @property (nonatomic, assign) NSInteger beautyType; @property (nonatomic, strong) NSMutableArray *arr; @end @implementation MHBeautyView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self addSubview:self.collectionView]; self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:MHBlackAlpha]; NSDictionary *indexDic = [[NSUserDefaults standardUserDefaults] objectForKey:kMHBeautyTitle]; if(IsDictionaryWithAnyKeyValue(indexDic)){ NSNumber *index = indexDic.allValues.firstObject; if(index){ self.lastIndex = index.integerValue; }else{ self.lastIndex = -1; } } } return self; } - (void)configureBeautyData:(NSMutableArray *)beautyArr{ self.array = beautyArr; [self.collectionView reloadData]; } - (void)clearAllBeautyEffects { for (int i = 0; i= 0) { MHBeautiesModel *lastModel = self.array[self.lastIndex]; lastModel.isSelected = NO; } NSDictionary *indexDic = @{currentModel.beautyTitle:@(indexPath.row)}; [[NSUserDefaults standardUserDefaults] setValue:indexDic forKey:kMHBeautyTitle]; if (indexPath.row == 0) { [self clearAllBeautyEffects]; }else{ MHBeautiesModel *firstModel = self.array[0]; firstModel.isSelected = NO; } self.lastIndex = indexPath.row; [self.collectionView reloadData]; NSString *beautKey = [NSString stringWithFormat:@"beauty_%ld",(long)currentModel.type]; NSInteger currentValue = [[NSUserDefaults standardUserDefaults] integerForKey:beautKey]; if ([self.delegate respondsToSelector:@selector(handleBeautyEffects:sliderValue:name:)]) { [self.delegate handleBeautyEffects:currentModel.type sliderValue:currentValue name:currentModel.beautyTitle]; } } #pragma mark - lazy //- (NSMutableArray *)array { // if (!_array) { // NSMutableArray * selectedItemArray = [MHSDK shareInstance].skinArray; // NSString *path = [[NSBundle mainBundle] pathForResource:@"MHBeautyParams" ofType:@"plist"]; // NSArray *items = [NSArray arrayWithContentsOfFile:path]; // // NSMutableArray * selectedItems = [NSMutableArray array]; // for (int i = 0; i < selectedItemArray.count; i ++) { // NSDictionary * selectedItemDic = selectedItemArray[i]; // NSString * selectedName = selectedItemDic[@"name"]; // for (int j = 0; j < items.count; j++) { // NSDictionary * itemDic = items[j]; // NSString * itemName = itemDic[@"name"]; // if ([selectedName isEqual:itemName]) { // [selectedItems addObject:itemDic]; // } // } // } // _array = [NSMutableArray array]; // NSString *title = [[NSUserDefaults standardUserDefaults] valueForKey:kMHBeautyTitle]; // for (int i = 0; i 0) { //// model.originalValue = [NSString stringWithFormat:@"%ld",originalValue]; //// [[NSUserDefaults standardUserDefaults] setInteger:originalValue forKey:beautKey]; //// } // [_array addObject:model]; // } // } // return _array; //} - (UICollectionView *)collectionView { if (!_collectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 0; layout.minimumInteritemSpacing = 0; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; layout.sectionInset = UIEdgeInsetsMake(20, 20,20,20); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, window_width,self.frame.size.height) collectionViewLayout:layout]; _collectionView.backgroundColor = [UIColor clearColor]; _collectionView.delegate = self; _collectionView.dataSource = self; [_collectionView registerClass:[MHBeautyMenuCell class] forCellWithReuseIdentifier:@"MHBeautyMenuCell"]; } return _collectionView; } - (NSInteger)currentIndex{ return _lastIndex; } @end