美文网首页iOS DeveloperiOS 实用技术
关于项目首页的一些整理

关于项目首页的一些整理

作者: 忘仙 | 来源:发表于2016-07-13 11:45 被阅读76次

1.关于布局方式

首页本想采用collectionView加瀑布流方式,可是后来由于中间有轮播,要8个section,放弃了这种写法。
那就自定义cell吧,可是每一组cell 都不同,所以反复创建了多种cell。在此期间也出现了一些问题。比如一个cell中有一个大item和4个小Item组成,开始想大的占两个cell高度,剩下的排在大item后面,可是却排在了下面,应该是flowLayout的问题,如果重写,那么每个都要写,又给否定了。
然后想着那就用for-Loop来创建吧,可是给写在setter 方法里面了,导致每次滑动都会创建,使得图册无限叠加,耗费内存。后来写在init方法中避免了叠加。

2.关于cell的item和出现分割线问题

第3个section有8个Item,想着那就用collection的优势来创建吧,却没想到被几条线击碎了。Item之间的线没有出头,那就画吧,可是一会显示,一会不显示,甚是折腾

在自定义CollectionCell的时候,添加一下代码
UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.top.mas_equalTo(self.mas_top);
        make.right.mas_equalTo(self.mas_right);
        make.bottom.mas_equalTo(self.mas_bottom);
    }];

剩下的控件添加到view上就可以了

后来即将要上线,索性写了个view上面放了8个imageView和label,还有要求的间隔线。虽然问题解决了,但是仔细想想,好像是完全放弃了collection的优势,有些遗憾。此处还得继续寻找更加合适的方案

3.关于collection刷新指定section或者row的问题

在iOS7 中reloadItemsAtIndexPaths 这个方法竟然会崩溃,找了好多资料,都没有找到解决方法,只能 全部刷新了,看起来没有多大的视觉变化,可是内存会有增加

Talk is cheap,show me the code:

// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:2];
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:1 inSection:2];
[UIView performWithoutAnimation:^{//这个animation可以消除刷新的动画
    if (IOS_VERSION < 8.0) {
        [_collectionView reloadData];
    }else{
        [_collectionView reloadItemsAtIndexPaths:@[indexPath]];
    }
}];

4.那么问题来了

一个cell中有8个imageView,用delegate看来是不行了,只能给每个imageView添加了手势,又导致 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{}这个方法没有使用到。

5.关于渐变式导航栏,不想多说,看code吧

-(void)viewWillAppear:(BOOL)animated{
    [superviewWillAppear:animated];
     if (self.navigationController) {
        [self.navigationControllersetNavigationBarHidden:YES animated:animated];
    }
}
-(void)viewDidDisappear:(BOOL)animated{    
    [superviewDidDisappear:animated];  
    if (self.navigationController) {
        [self.navigationControllersetNavigationBarHidden:NOanimated:NO];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.y < 0) {
        [selfshowView:_naviViewhidden:YES];
        [selfsetStatusBarStyle:UIStatusBarStyleDefault];   
    }else if(scrollView.contentOffset.y > 50) {
        [selfshowView:_naviViewhidden:NO];
        CGFloat alpha = MIN(1, 1 - ((50 + 64 - scrollView.contentOffset.y) / 64));
        [_naviViewsetBackgroundColor:[[UIColorwhiteColor] colorWithAlphaComponent:alpha]];
    }else{
        [selfshowView:_naviViewhidden:NO];
        [_naviViewsetBackgroundColor:[[UIColorwhiteColor] colorWithAlphaComponent:0.0f]];
    }
}

-(void)showView:(UIView *)view hidden:(BOOL)hidden{      
        CATransition *animation = [CATransitionanimation];        
        animation.type = kCATransitionFade;    
        animation.duration = 0.4;    
        [view.layeraddAnimation:animation forKey:nil];    
        view.hidden = hidden;
}
//根据数组随机生成一个长度为3内容不重复的数组
-(NSArray*)createRandomArray:(NSMutableArray*)mutableArray{
    
    if (mutableArray.count < 4) {
        return mutableArray;
    }else{
        NSMutableArray *startArray = [NSMutableArray array];
        NSMutableArray *resultArray=[[NSMutableArray alloc] initWithCapacity:0];
        for (NSInteger i = 0; i < mutableArray.count; i++) {
            [startArray addObject:[NSString stringWithFormat:@"%ld",i]];
        }
        for (int i = 0; i<3; i++) {
            int t = arc4random()%startArray.count;
            resultArray[i] = startArray[t];
            startArray[t] = [startArray lastObject];
            [startArray removeLastObject];
        }
        NSInteger i = [resultArray[0] integerValue];
        NSInteger j = [resultArray[1] integerValue];
        NSInteger k = [resultArray[2] integerValue];
        
        return @[mutableArray[i], mutableArray[j], mutableArray[k]];
    }
}

小结:此次虽然完成改版,但是还是有许多可优化更改的地方,仙路漫漫,道友仍需努力!

相关文章

  • 关于项目首页的一些整理

    1.关于布局方式 首页本想采用collectionView加瀑布流方式,可是后来由于中间有轮播,要8个sectio...

  • hexo个人博客 前端+后台

    体验链接 点我体验喽 项目结构 功能讲解 功能预览首页分类标签关于归档新增编辑聊天(正在添加) 首页 内容 项目说...

  • 02_小程序的布局

    普通的小程序开发者工具 项目具备的一些功能 首先,是项目的首页.在首页可以切换到城市列表,也可以切换到用户中心 ,...

  • Ionic4 学习笔记(二):首页制作,创建其他页面

    首页的制作 因为项目从简,所以,整体内容也不多,这里首页只放如下几个内容: 标题 数独游戏按钮 设置按钮 关于按钮...

  • 开源工具集合

    应用性能监控(APM) skywalking项目 skywalking首页zipkin项目 zipkin首页 ...

  • app首页新解读:如何设计总有一款你喜欢的首页?

    本文是最近在做竞品分析,在分析竞品的首页时,整理的一些有关首页的想法。想看别人家的首页都是什么样子的就快快来看吧!...

  • 项目代码优化、编程思想与重构

    最近为项目组整理相关项目相关的规范文档,并整理了项目中,代码中的一些问题,识别项目代码中的一些可以优化的代码...

  • 项目管理杂谈

    基础 前两天朋友问我关于项目管理的一些体会,于是便整理成此文,希望与您探讨。 我觉得项目管理的核心就是两个“度”,...

  • 获取项目列表

    1.项目首页 说明:获取项目的首页列表 URL http://localhost:8080/glove/item/...

  • Angulars分页加载功能详解

    因公司项目要求 最近在写H5项目 遇到了关于分页加载list列表的问题 网上差了一些资料 经过自己整理 完美的实现...

网友评论

    本文标题:关于项目首页的一些整理

    本文链接:https://www.haomeiwen.com/subject/twbsjttx.html