#import "ViewController.h"
@interface
ViewController ()
@property
(weak,
nonatomic
)
IBOutlet
UITableView *testTableView;
@property
(weak,
nonatomic
)
IBOutlet
NSLayoutConstraint
*bottomLine;
@property
(weak,
nonatomic
)
IBOutlet
NSLayoutConstraint
*topLine;
@property
(weak,
nonatomic
)
IBOutlet
NSLayoutConstraint
*topLine2;
@property
(weak,
nonatomic
)
IBOutlet
NSLayoutConstraint
*bottomLine2;
@property
(strong,
nonatomic
) CADisplayLink *displayLink;
@property
(assign,
nonatomic
)
int
count;
@property
(strong,
nonatomic
)
NSArray
*dataArray;
@end
@implementation
ViewController
- (
void
)viewDidLoad {
[
super
viewDidLoad];
self
.count = 0;
self
.testTableView.delegate =
self
;
self
.testTableView.dataSource =
self
;
self
.displayLink = [CADisplayLink displayLinkWithTarget:
self
selector:
@selector
(tick:)];
[
self
.displayLink addToRunLoop:[
NSRunLoop
currentRunLoop]
forMode:
NSDefaultRunLoopMode
];
self
.dataArray = [
NSArray
arrayWithObjects:
@"1"
,
@"2"
,
@"3"
,
@"4"
,
@"5"
,
@"1"
,
@"2"
,
@"3"
,
@"4"
,
@"5"
,
nil
];
[
self
.testTableView setContentOffset:CGPointMake(0, 0) animated:
YES
];
self
.testTableView.userInteractionEnabled =
NO
;
}
- (
void
) tick:(CADisplayLink *)displayLink {
self
.count ++;
[
self
.testTableView setContentOffset:CGPointMake(0, ((25.0 / 30.0) * (
float
)
self
.count)) animated:
NO
];
if
(
self
.count >= 300) {
self
.count = 0;
}
}
- (
void
)didReceiveMemoryWarning {
[
super
didReceiveMemoryWarning];
}
- (
NSInteger
)tableView:(UITableView *)tableView numberOfRowsInSection:(
NSInteger
)section {
return
self
.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(
NSIndexPath
*)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
@"cell"
];
if
(cell ==
nil
) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:
@"cell"
];
}
cell.textLabel.text =
self
.dataArray[indexPath.row];
cell.backgroundColor = [UIColor clearColor];
return
cell;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(
NSIndexPath
*)indexPath {
return
50;
}
- (
void
)dealloc {
[
self
.displayLink invalidate];
self
.displayLink =
nil
;
}
@end