123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- //
- // EmojiPackgeViewController.m
- // shiku_im
- //
- // Created by JayLuo on 2019/12/13.
- // Copyright © 2019 Reese. All rights reserved.
- //
- #import "EmojiPackgeViewController.h"
- #define SD_WEBP 1
- #import "UIImageView+WebCache.h"
- #import "UIImage+WebP.h"
- @interface EmojiPackgeViewController ()<UIScrollViewDelegate>
- @property (nonatomic, assign) int margin;
- @property (nonatomic, assign) int tempN;
- @property (nonatomic, assign) int maxPage;
- @property (nonatomic, strong) UIScrollView *sv;
- @property (nonatomic, strong) UIPageControl *pc;
- @property (nonatomic, strong) NSMutableArray *delBtns;
- @property (nonatomic, strong) NSMutableArray *emojis;
- @end
- @implementation EmojiPackgeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- _delBtns = [NSMutableArray array];
- _emojis = [NSMutableArray array];
-
- _margin = 18;
- // tempN = (JX_SCREEN_WIDTH <= 320) ? 8:10;
- _tempN = JX_SCREEN_WIDTH / (60 + _margin);
-
- if (((_tempN + 1) * 60 + _tempN * _margin) <= JX_SCREEN_WIDTH) {
- _tempN += 1;
- }
-
- _margin = (JX_SCREEN_WIDTH - _tempN * 60) / (_tempN + 1);
-
- // if (_emojis.count <= 0) {
- // [g_server userCollectionListWithType:6 pageIndex:0 toView:self];
- // [g_server userEmojiListWithPageIndex:0 toView:self]; 原来
- // [g_server faceClollectListType:@"1" View:self];
- // [g_server getFaceDetail:_model.name View:self];
- // }
-
- // [g_notify addObserver:self selector:@selector(refresh) name:kFavoritesRefresh object:nil];
- }
- - (void)setModel:(JLFacePackgeModel *)model {
- _model = model;
-
- [_emojis removeAllObjects];
-
- for (NSDictionary *tempDict in model.images) {
- NSString *tem = tempDict[@"url"];
- [_emojis addObject:tem];
- }
- [self refresh];
- }
- - (void)dealloc {
- [g_notify removeObserver:self];
- }
- -(void)create {
-
- int m = fmod([_emojis count], (_tempN * 2));
- _maxPage = (int)[_emojis count]/(_tempN*2);
- if(m != 0)
- _maxPage++;
-
- [self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
- [_delBtns removeAllObjects];
-
- _sv = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-20)];
- _sv.contentSize = CGSizeMake(WIDTH_PAGE*_maxPage, self.view.frame.size.height-20);
- _sv.pagingEnabled = YES;
- _sv.scrollEnabled = YES;
- _sv.delegate = self;
- _sv.showsVerticalScrollIndicator = NO;
- _sv.showsHorizontalScrollIndicator = NO;
- _sv.userInteractionEnabled = YES;
- _sv.minimumZoomScale = 1;
- _sv.maximumZoomScale = 1;
- _sv.decelerationRate = 0.01f;
- _sv.backgroundColor = [UIColor clearColor];
- self.view.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:_sv];
- // [_sv release];
-
-
- int n = 0;
- int startX = (JX_SCREEN_WIDTH - _tempN * 60 - (_tempN - 1) * _margin) / 2;
-
- for(int i=0;i<_maxPage;i++){
- int x=WIDTH_PAGE*i + startX,y=0;
- for(int j=0;j<_tempN * 2;j++){
- if(n>=[_emojis count])
- break;
- JXImageView *iv = [[JXImageView alloc] initWithFrame:CGRectMake(x, y+10, 60, 60)];
- iv.tag = n;
- // NSDictionary *dict = _emojis[n];
- // NSArray *urlArray = dict[@"path"];
- NSString *url = _emojis[n];
- [iv sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"Default_Gray"] options:(SDWebImageRetryFailed)];
- iv.delegate = self;
- iv.didTouch = @selector(actionSelect:);
- [_sv addSubview:iv];
-
- // 长按删除手势
- UILongPressGestureRecognizer *lg = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longGestureAction:)];
- [iv addGestureRecognizer:lg];
-
- // 删除按钮
- JXImageView* del = [[JXImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(iv.frame) - 15, iv.frame.origin.y - 5, 20, 20)];
- del.didTouch = @selector(onDelete:);
- del.delegate = self;
- del.tag = n;
- del.image = [UIImage imageNamed:@"delete"];
- del.hidden = YES;
- [_sv addSubview:del];
- [_delBtns addObject:del];
-
- if ((j + 1) % _tempN == 0) {
- x = WIDTH_PAGE*i + startX;
- y += 70;
- }else {
- x += 60 + _margin;
- }
-
- n++;
- }
- }
-
- _pc = [[UIPageControl alloc]initWithFrame:CGRectMake(100, self.view.frame.size.height-100, JX_SCREEN_WIDTH-200, 30)];
- _pc.numberOfPages = _maxPage;
- _pc.pageIndicatorTintColor = [UIColor grayColor];
- _pc.currentPageIndicatorTintColor = [UIColor blackColor];
- _pc.userInteractionEnabled = NO;
- [_pc addTarget:self action:@selector(actionPage) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:_pc];
- }
- - (void)refresh {
- // [g_server getFaceDetail:_model.name View:self];
- [self create];
- }
- // 点击发送
- -(void)actionSelect:(UIView*)sender
- {
- // NSDictionary *dict = [_emojis objectAtIndex:sender.tag];
- // NSString* s = dict[@"url"];
- NSString* s = [_emojis objectAtIndex:sender.tag];
- if ([self.delegate respondsToSelector:@selector(selectEmojiPackgeWithString:)]) {
- [self.delegate selectEmojiPackgeWithString:s];
- }
-
- }
- // 长按显示删除按钮
- - (void)longGestureAction:(UILongPressGestureRecognizer *)gestureRecognizer {
- return;
- if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
- NSInteger n = gestureRecognizer.view.tag;
- for (NSInteger i = 0; i < _delBtns.count; i ++) {
- JXImageView *iv = _delBtns[i];
- if (i == n) {
- iv.hidden = !iv.hidden;
- }else {
- iv.hidden = YES;
- }
-
- }
-
- }
- }
- // 删除
- //- (void)onDelete:(UIView *)view {
- // NSInteger n = view.tag;
- // if ([self.delegate respondsToSelector:@selector(deleteFavoritWithString:)]) {
- // NSDictionary *dict = [_emojis objectAtIndex:n];
- // NSString* s = dict[@"id"];
- // [self.delegate deleteFavoritWithString:s];
- // [_emojis removeObjectAtIndex:n];
- // [self create];
- // }
- //
- //}
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
-
- for (NSInteger i = 0; i < _delBtns.count; i ++) {
- JXImageView *iv = _delBtns[i];
- iv.hidden = YES;
- }
- }
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
- {
- int index = scrollView.contentOffset.x/JX_SCREEN_WIDTH;
- int mod = fmod(scrollView.contentOffset.x,JX_SCREEN_WIDTH);
- if( mod >= JX_SCREEN_WIDTH/2)
- index++;
- _pc.currentPage = index;
- }
- - (void) setPage
- {
- _sv.contentOffset = CGPointMake(WIDTH_PAGE*_pc.currentPage, 0.0f);
- [_pc setNeedsDisplay];
- }
- -(void)actionPage{
- [self setPage];
- }
- -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
-
- if ([aDownload.action isEqualToString:act_userEmojiList]) {
-
- [_emojis removeAllObjects];
- [_emojis addObjectsFromArray:array1];
-
- [self create];
-
- }
-
- if ([aDownload.action isEqualToString:act_FaceClollectList]) {
-
-
- // NSLog(@"----%@---%@", dict, array1);
- [_emojis removeAllObjects];
- [_emojis addObjectsFromArray:array1];
-
- [self create];
-
- }
-
- if ([aDownload.action isEqualToString:act_FaceGetName]) {
-
-
- // NSLog(@"----%@---%@", dict, array1);
- [_emojis removeAllObjects];
-
- if (array1.count>0) {
- NSDictionary *tempDict = array1.firstObject;
- NSArray *emojiUrlArray = tempDict[@"images"];
- [_emojis addObjectsFromArray:emojiUrlArray];
- }
-
-
- [self create];
-
- }
-
- }
- -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
-
- return hide_error;
- }
- -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
-
- return hide_error;
- }
- -(void) didServerConnectStart:(JXConnection*)aDownload{
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #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
|