实践-小效果 V

1.搜索关键字高亮显示

搜索关键字高亮显示Dome

image.png

2.动态改变tableHeaderView的高度

表头展开折叠.gif
 headAllView.tapChangeFrame = ^(void) {
    [weakSelf.Tb beginUpdates];
    [weakSelf.Tb setTableHeaderView:weakHeadAllView];
    [weakSelf.Tb endUpdates];

};
self.Tb.tableHeaderView = headAllView;

关键效果设置:在改变tableHeaderView的高度后,再手动调用下 Tb 的 setTableHeaderView方法。

3.MBProgressHUD文字多时换行展示

@implementation MBProgressHUD (CXRExpand)

+ (void)showText:(NSString *)text image:(NSString *)image toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication] keyWindow];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    if (text.length>15) {
        hud.detailsLabelText = text;
    }else{
        hud.labelText =text;
    }
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", image]]];
    hud.mode = MBProgressHUDModeCustomView;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1.5];
 }

修改MBProgressHUD里面的源文件即可实现。

4.扫描身份证快速读取信息、扫描银行卡获取卡号

身份证扫描


银行卡扫描

5.UIButton文本竖着排列


你可能找不到这样的设置,但是可以这样简单的实现。

  [selectButton setTitle:@"查\n询" forState:UIControlStateNormal];
  selectButton.titleLabel.numberOfLines = 0;

6. 输入框后面带上单位

- (void)setMyRightText :(NSString *)rightText;
{
    if (rightText.length>0) {
        UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0,0, Scale_X(60), Scale_Y(20))];
        label.textColor=GrayTextColor;
        [label setBackgroundColor:[UIColor clearColor]];
        label.text=rightText;
        [label setFont:[UIFont fontWithName:@"Helvetica" size:MEDIUM_FONT]];
        label.textAlignment = NSTextAlignmentRight;
        self.rightViewMode = UITextFieldViewModeAlways;
        self.rightView = label ;
    }
}

可以在自定义的UITextFeild的类中实现如下方法,关键是rightViewMode的设置,默认是不显示的。

7. 为Cell增加动效

实现方法是在TableView加载后增加整体的动效,通过循环和延迟,让每个Cell从不同的时间开始经历相同的时间动效结束。

- (void)viewDidAppear:(BOOL)animated
{
    [self animateStart];
}
- (void)animateStart
{
    NSArray *array = [Tb visibleCells];
    [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UITableViewCell *cell = (UITableViewCell*)obj;
        cell.transform = CGAffineTransformMakeTranslation(0, Tb.bounds.size.height);
        [UIView animateWithDuration:1 delay:0.05*idx usingSpringWithDamping:0.8 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseIn animations:^{
            cell.transform = CGAffineTransformMakeTranslation(0, 0);
        } completion:^(BOOL finished) {
            
        }];
    }];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    cell.frame = CGRectMake(-Tb.bounds.size.width, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
    [UIView animateWithDuration:0.2 delay:0.2*indexPath.row options:UIViewAnimationOptionCurveEaseIn animations:^{
        cell.frame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
    } completion:^(BOOL finished) {
        
    }];
}
cell点击.gif
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [Tb cellForRowAtIndexPath:indexPath];
    NSTimeInterval animationDuration =0.05;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:animationDuration];
    cell.transform = CGAffineTransformMakeScale( 0.9, 0.9);
    [UIView commitAnimations];
}

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [Tb cellForRowAtIndexPath:indexPath];
    NSTimeInterval animationDuration =1;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:animationDuration];
    cell.transform = CGAffineTransformIdentity;
    [UIView commitAnimations];
}
 上面两个方法调用后,会调用这个方法。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
}

8. 网易顶部类似多类目选择视图

1.创建很多ChildViewController

 //推荐
CY1ViewController *message = [[CY1ViewController alloc] init];
message.title = @"推荐";
[self addChildViewController:message];
//赛事
CY2ViewController *comp = [[CY2ViewController  alloc] init];
comp.title = @"赛事";
[self addChildViewController:comp];
.....

2.创建很多对应的Button

 for (int i = 0; i < self.childViewControllers.count; ++i) {
    
    UIViewController *vc = self.childViewControllers[i];
    
    UIButton *btn = [[UIButton alloc] init];;
    btn.frame = CGRectMake(btnW * i , 0, btnW, btnH);
    [btn setTitle:vc.title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(topTitleBtnClick:) forControlEvents:UIControlEventTouchDown];
    btn.tag = i;
    [view addSubview:btn];
    
    if (btn.tag == 0) {
        [self topTitleBtnClick:btn];
    }
    
    [self.titleButton addObject:btn];  //一个数组
}

3.Button的点击事件,放大当前的按钮恢复上一个点击的按钮,并滚动SC。

- (void)selctedBtn:(UIButton *)btn
{
    [_selectBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self setupTitleButtonCenter:btn];
    _selectBtn.transform = CGAffineTransformIdentity;
    btn.transform = CGAffineTransformMakeScale(1.3, 1.3);

    //上次点击的按钮
    _selectBtn = btn;
}

- (void)setUpOnechildController:(UIButton *)btn
{
  UIViewController *vc = self.childViewControllers[btn.tag];
  if (!vc.view.superview) {
      vc.view.frame = CGRectMake(btn.tag * kScreenW, 64, kScreenW, kScreenH - 64);
     [self.contentScroll addSubview:vc.view];
  };
  self.contentScroll.contentOffset = CGPointMake(btn.tag *kScreenW, 0);
}

9.左右大面积侧滑

侧滑.gif

要实现这样的效果,先看图层关系:


WWSideslipViewController是一个VC,在WWSideslipViewController的View上依次放上如下子视图:

- 星空背景ImageView;
- LeftVC的View
- RightVC的View
- MainVC的View(效果图中是放了一个QQ主页的截图)

给MainVC的View加手势,根据手势,动态改变MainVC的View的外形并隐藏/展示 LeftVC的View或者 rightVC的View即可。

  WWSideslipViewController 中

    //滑动手势
    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
    [mainControl.view addGestureRecognizer:pan];
    
    //单击手势
    sideslipTapGes= [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handeTap:)];
    [sideslipTapGes setNumberOfTapsRequired:1];
    
    [mainControl.view addGestureRecognizer:sideslipTapGes];
    
    leftControl.view.hidden = YES;
    righControl.view.hidden = YES;
    
    [self.view addSubview:leftControl.view];
    [self.view addSubview:righControl.view];
    
    [self.view addSubview:mainControl.view];

10.点击cell中的UIImageView全屏展示并关闭

点击.gif

actionTap 是cell中的图片上加的手势事件。

-(void)actionTap:(UITapGestureRecognizer *)sender{
    
    CGPoint location = [sender locationInView:self.tableView];
    NSIndexPath *indexPath  = [self.tableView indexPathForRowAtPoint:location];
    
    UITableViewCell *cell = (UITableViewCell *)[self.tableView  cellForRowAtIndexPath:indexPath];
    UIImageView *imageView=(UIImageView *)[cell.contentView viewWithTag:9999];
    
    //记录下点击的图片位置
    frame_first=CGRectMake(cell.frame.origin.x+imageView.frame.origin.x, cell.frame.origin.y+imageView.frame.origin.y-self.tableView.contentOffset.y, imageView.frame.size.width, imageView.frame.size.height);
    

    fullImageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height)];
    fullImageView.backgroundColor=[UIColor blackColor];
    fullImageView.userInteractionEnabled=YES;
    [fullImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap2:)]];   //添加轻击手势
    fullImageView.contentMode=UIViewContentModeScaleAspectFit;
    
    if (![fullImageView superview]) {
        
        fullImageView.image=imageView.image;
        [self.view.window addSubview:fullImageView];
        fullImageView.frame=frame_first;
        [UIView animateWithDuration:0.5 animations:^{
            
            fullImageView.frame=CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height);
            
            
        } completion:^(BOOL finished) {
            
            [UIApplication sharedApplication].statusBarHidden=YES;
            
        }];
    }
}

-(void)actionTap2:(UITapGestureRecognizer *)sender{

    [UIView animateWithDuration:0.5 animations:^{
        fullImageView.frame=frame_first;
    } completion:^(BOOL finished) {
        [fullImageView removeFromSuperview];
    }];

  [UIApplication sharedApplication].statusBarHidden=NO;

}

点评:其实这样的效果并不难,如果把cell中的UIImageView换成UIbutton就很简单了,很容易找到那个image,可是那样的话需要点击进去才能触发事件,而不是轻击。也算给我们提供一种根据手势点击获取cell的思路。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 221,695评论 6 515
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,569评论 3 399
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 168,130评论 0 360
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,648评论 1 297
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,655评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,268评论 1 309
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,835评论 3 421
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,740评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,286评论 1 318
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,375评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,505评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,185评论 5 350
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,873评论 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,357评论 0 24
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,466评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,921评论 3 376
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,515评论 2 359

推荐阅读更多精彩内容