UITableViewCell状态切换效果

简介:

UITableViewCell状态切换效果

 

效果图

 

源码

https://github.com/YouXianMing/Animations


//
//  TableViewTapAnimationController.m
//  Animations
//
//  Created by YouXianMing on 15/11/27.
//  Copyright © 2015年 YouXianMing. All rights reserved.
//

#import "TableViewTapAnimationController.h"
#import "TableViewTapAnimationCell.h"
#import "UIView+SetRect.h"
#import "TapAnimationModel.h"

@interface TableViewTapAnimationController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView   *tableView;
@property (nonatomic, strong) NSArray       *dataArray;

@end

@implementation TableViewTapAnimationController

- (void)viewDidLoad {
    
    [super viewDidLoad];
}

- (void)setup {
    
    [super setup];
    
    // Init dataArray.
    _dataArray = @[[TapAnimationModel modelWithName:@"YouXianMing" selected:YES],
                   [TapAnimationModel modelWithName:@"NoZuoNoDie" selected:NO],
                   [TapAnimationModel modelWithName:@"Animations" selected:NO]];
    
    // Init TableView.
    self.tableView                = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.width, self.view.height - 64)
                                                                 style:UITableViewStylePlain];
    self.tableView.delegate       = self;
    self.tableView.dataSource     = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[TableViewTapAnimationCell class] forCellReuseIdentifier:@"TableViewTapAnimationCell"];
    [self.view addSubview:self.tableView];
    
    [self bringTitleViewToFront];
}

#pragma mark - TableView相关方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    TableViewTapAnimationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewTapAnimationCell"];
    cell.data                       = _dataArray[indexPath.row];
    [cell loadContent];
    [cell changeStateAnimated:NO];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    TableViewTapAnimationCell *cell = (TableViewTapAnimationCell *)[tableView cellForRowAtIndexPath:indexPath];
    [cell showSelectedAnimation];
    [cell changeStateAnimated:YES];
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 80.f;
}

@end

细节

 


目录
相关文章
UIRefreshControl代码刷新
UIRefreshControl代码刷新
54 0
|
Android开发
Android软键盘状态的切换及其强制隐藏
MainActivity如下:package cc.c; import android.os.Bundle; import android.view.
826 0
自定义状态切换按钮
最近在做一个项目,一个界面的按钮UI给画成了这样(默认状态是蓝色的然后触摸后变成灰色的) UI效果 然后本着给低版本系统APP适配的职业素养(其实是不想画这种按钮),想让UI兄弟给将图标改成整个按钮效果的图片,可是。
918 0
解决使用tableview的reloadSections刷新之后,sectionFooter有时会消失
//CATransaction解决刷新之后sectionFooter消失的问题 [CATransaction begin]; [CATransaction setCompletionBlock:^{ [self.
1433 0
解决Tap手势和UITableView点击冲突
通常是在UIGestureRecognizer的代理函数中进行操作 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 两种思路: 根据touch的view的类型进行判断 //example -(BOOL)gest
1259 0