Repository navigation
Expand file tree
/
Copy pathViewController.m
More file actions
121 lines (96 loc) · 2.83 KB
/
Copy pathViewController.m
File metadata and controls
121 lines (96 loc) · 2.83 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// ViewController.m
// ccccc
//
// Created by ze on 16/1/12.
// Copyright © 2016年 ze. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate>
@property (nonatomic, strong)UIView *headv;
@property (nonatomic, strong)UIView *floatingView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITableView *_tb = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 568) style:UITableViewStylePlain];
_tb.tableHeaderView = [self headv];
_tb.delegate = self;
_tb.dataSource = self;
[self.view addSubview:_tb];
[self addInHeader];
}
- (void)addInHeader
{
[self.floatingView removeFromSuperview];
[self.headv addSubview:self.floatingView];
CGRect r = self.floatingView.frame;
r.origin.y = 200 - 50;
self.floatingView.frame = r;
}
- (void)addInSelf
{
[self.floatingView removeFromSuperview];
[self.view addSubview:self.floatingView];
[self.view bringSubviewToFront:self.floatingView];
CGRect r = self.floatingView.frame;
r.origin.y = 64;
self.floatingView.frame = r;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"scr y :%@", @(scrollView.contentOffset.y));
CGFloat delta = 150 - scrollView.contentOffset.y;
NSLog(@"delta %@", @(delta));
if (delta <= 64) {
if ([self.headv.subviews containsObject:self.floatingView]) {
[self addInSelf];
}
}
else{
if ([self.view.subviews containsObject:self.floatingView]) {
[self addInHeader];
}
}
}
- (UIView *)headv
{
if (!_headv) {
_headv = ({
UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 200)];
v.backgroundColor = [UIColor cyanColor];
v;
});
}
return _headv;
}
- (UIView*)floatingView
{
if (!_floatingView) {
_floatingView = ({
UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
v.backgroundColor = [UIColor redColor];
v;
});
}
return _floatingView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 12;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *const ide = @"ide";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ide];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ide];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@", @(indexPath.row)];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end