//
// ViewController.m
// TableViewCellScaleTestDemo
//
// Created by 刘光军 on 15/12/30.
// Copyright © 2015年 刘光军. All rights reserved.
//
#import "ViewController.h"
#import "UIView+YYAdd.h"
//cell
@interface MyCell : UITableViewCell
@property(nonatomic, strong) UILabel* label;/**< label */
-(void)setWithString:(NSString *)string;
@end
@implementation MyCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor clearColor];
UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
imageView.image = [UIImage imageNamed:@"mew_interlaced"];
imageView.backgroundColor = [UIColor yellowColor];
[self.contentView addSubview:imageView];
self.label = [[UILabel alloc] initWithFrame:CGRectMake(120, 10, self.frame.size.width - 120 - 20, 100)];
_label.textColor = [UIColor colorWithWhite:0.7 alpha:1.0];
self.label.font = [UIFont systemFontOfSize:20];
[self.contentView addSubview:self.label];
}
return self;
}
- (void)setWithString:(NSString *)string {
self.label.text = [NSString stringWithFormat:@"我是第%@行", string];
}
@end
//controller
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong) UITableView* tableView;/**< tableView */
@property(nonatomic, strong) NSArray* arr;/**< array */
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithRed:0.22 green:0.22 blue:0.22 alpha:1];
_arr = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28", nil];
[self configTabelView];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark -tableview
- (void)configTabelView {
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.backgroundColor = [UIColor colorWithRed:0.22 green:0.22 blue:0.22 alpha:1];
[self.view addSubview:self.tableView];
}
#pragma mark - 设置cell分割线靠右
-(void)viewDidLayoutSubviews {
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}
#pragma mark - tableview代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[cell setWithString:[_arr objectAtIndex:indexPath.row]];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 140;
}
#pragma mark 设置scale
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat viewHeight = scrollView.height + scrollView.contentInset.top;
for (MyCell *cell in [self.tableView visibleCells]) {
CGFloat y = cell.centerY - scrollView.contentOffset.y;
CGFloat p = y - viewHeight / 2;
CGFloat scale = cos(p / viewHeight * 0.8) * 0.95;
[UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState animations:^{
cell.contentView.transform = CGAffineTransformMakeScale(scale, scale);
} completion:NULL];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
iOStableView的滑动动画
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- InfiniteCycleViewPager 项目里有一个 HorizontalInfiniteCycleView...
- 好久没写过文章了,趁现在得空写一下最近实现的UICollectionViewFlowLayout实现的左右滑动功能...
- 其实,上天给了我十万条理由让我去使用系统的导航栏,然而,仅仅只因为一条,我不得不放弃,我们坑爹的产品经理不喜欢。。...
- 30岁正是经过了5-7年的职场生涯,技术、经验、职业素养等各方面都到了一个比较充沛的阶段。如果前几年不是在混日子,...