单军华
2018-03-28 f99cf1d5cc50407394501853be06cb39f38a092c
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
//
//  view1.m
//  test
//
//  Created by 博爱 on 16/5/11.
//  Copyright © 2016年 博爱之家. All rights reserved.
//
 
#import "view1.h"
 
@interface view1 ()
<
    UITableViewDelegate,
    UITableViewDataSource
>
{
    BOOL isShowAnimation;
}
@property (nonatomic, strong) NSMutableArray  *titlesArray;
@property (nonatomic, strong) NSMutableArray  *classNamesArray;
@property (nonatomic, strong) NSMutableArray  *contentsArray;
 
@property (nonatomic, strong) NSMutableArray  *dataArray;
 
/*! viewModel:BAHomeViewModel */
@property (nonatomic, strong) NSMutableArray  *statusFrames;
 
 
 
 
@end
 
@implementation view1
 
- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] init];
//        _tableView.frame = CGRectMake(0, 0, BA_SCREEN_WIDTH, BA_SCREEN_HEIGHT - BA_getTabbarHeight);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorColor = [UIColor redColor];
        
        [self creatData];
        [self modelData];
        [self addSubview:_tableView];
        
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsMake(0 , 0, 0, 0));
        }];
        
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}
 
- (instancetype)initWithFrame:(CGRect)frame withSelectRowBlock:(selectRowBlock)selectRowBlock
{
    if (self = [super initWithFrame:frame])
    {
        self.selectBlock = selectRowBlock;
                
        self.tableView.hidden = NO;
        
        isShowAnimation = NO;
 
        [self viewDidLayoutSubviews];
        
 
    }
    return self;
}
 
 
 
- (void)creatData
{
    [self addCell:@"1、AFNetWorking的完美封装" content:@"封装AFN,实现简单的get和post请求,可以自定义请求头,可以解析json数据、xml数据、data数据,可以获取缓存数据。" class:@"DemoVC1"];
    [self addCell:@"2、清理缓存" content:@"清理网络请求缓存和图片缓存,可清理系统缓存!" class:@"DemoVC2"];
    [self addCell:@"3、点击button倒计时" content:@"两种比较常用的获取倒计时验证码的样式!新增一种自定义警告框,可以点击屏幕消失!新增了一种跑马灯广告效果,希望能帮助部分用户!" class:@"DemoVC3"];
    [self addCell:@"4、友盟分享和友盟登陆的完美封装" content:@"包含:微博、微信、朋友圈、QQ、空间、短信的分享和登陆,可以使用默认列表,也可以自定义单个分享和登陆!" class:@"DemoVC4"];
    [self addCell:@"5、正则表达式最新封装" content:@"包含:手机号码、运营商类型(判断移动、联通、电信)、邮箱、数字、中英文、URL、身份证号码等!还可以文字筛选高亮显示!" class:@"DemoVC5"];
    [self addCell:@"6、本地通知最新完美封装" content:@"最近整理了下本地通知和极光推送,有很多坑都踩过了,刚刚整理出来的完美封装,肯定适合大部分场合,也可以用此封装写闹钟,也提醒事件,都可以!【刚添加了本地通知的跳转事件处理!】如果喜欢,请在git上点个星吧!" class:@"DemoVC6"];
    [self addCell:@"7、webView和WKWebView完美封装" content:@"webView和WKWebView的封装,简单的内置浏览器,有简单的功能,后期有新功能会加上!如果喜欢,请在git上点个星吧!" class:@"DemoVC7"];
    [self addCell:@"8、系统提醒和日历提醒" content:@"最近做了一个预约功能,有用到系统提醒和日历提醒,就写了这个demo!如果喜欢,请在git上点个星吧!" class:@"DemoVC8"];
    [self addCell:@"9、流式布局和线性布局库的使用" content:@"用流式布局和线性布局库MyLayout,写了一个collectionView,如果喜欢,请在git上点个星吧!" class:@"DemoVC9"];
    [self addCell:@"10、collectionView的简单使用" content:@"用View写的写了一个简单的collectionView,可随意添加到任何地方,如果喜欢,请在git上点个星吧!" class:@"DemoVC10"];
    [self addCell:@"11、collectionView的浮动布局" content:@"自适应宽高的collectionView,自定义layout,如果喜欢,请在git上点个星吧!" class:@"DemoVC11"];
    [self addCell:@"12、各种自定义弹框" content:@"各种自定义弹框,系统的、自定义的弹框,如果喜欢,请在git上点个星吧!" class:@"DemoVC12"];
    [self addCell:@"13、GCD入门" content:@"GCD入门学习,小白可以看,大神自行绕过!如果喜欢,请在git上点个星吧!" class:@"DemoVC13"];
    [self addCell:@"14、OC的set/get 方法的区别!" content:@"OC的set/get 方法的区别!,小白可以看,大神自行绕过!如果喜欢,请在git上点个星吧!" class:@"DemoVC14"];
}
 
- (void)addCell:(NSString *)title content:(NSString *)content class:(NSString *)className
{
    [self.titlesArray addObject:title];
    [self.classNamesArray addObject:className];
    [self.contentsArray  addObject:content];
}
 
- (void)modelData
{
    for (int i = 0; i < self.titlesArray.count; i ++)
    {
//        BAHomeVCModel *model = [BAHomeVCModel new];
//        model.titleLabel = self.titlesArray[i];
//        model.contentLabel = self.contentsArray[i];
//        
//        [self.dataArray addObject:model];
    }
    
    // 模型转换视图模型 BAHomeVCModel -> BAHomeViewModel
    NSMutableArray *statusF = [NSMutableArray array];
//    for (BAHomeVCModel *model in self.dataArray)
//    {
//        BAHomeViewModel *subViewFrame = [[BAHomeViewModel alloc] init];
//        subViewFrame.viewModel = model;
//        [statusF addObject:subViewFrame];
//    }
    [self.statusFrames addObjectsFromArray:statusF];
}
 
- (NSMutableArray *)dataArray
{
    if (!_dataArray)
    {
        _dataArray = @[].mutableCopy;
    }
    return _dataArray;
}
 
- (NSMutableArray *)titlesArray
{
    if (!_titlesArray)
    {
        _titlesArray = @[].mutableCopy;
    }
    return _titlesArray;
}
 
- (NSMutableArray *)classNamesArray
{
    if (!_classNamesArray)
    {
        _classNamesArray = @[].mutableCopy;
    }
    return _classNamesArray;
}
 
- (NSMutableArray *)contentsArray
{
    if (!_contentsArray)
    {
        _contentsArray = @[].mutableCopy;
    }
    return _contentsArray;
}
 
- (NSMutableArray *)statusFrames
{
    if (!_statusFrames)
    {
        _statusFrames = @[].mutableCopy;
    }
    return _statusFrames;
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.statusFrames.count;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    // 创建cell
    UITableViewCell *cell = [[UITableViewCell alloc] init];
//    // 获取DemoVC15_ViewModel模型
//    BAHomeViewModel *subViewFrame = self.statusFrames[indexPath.row];
//    // 给cell传递模型
//    cell.subViewFrame = subViewFrame;
    
    return cell;
}
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *className = self.classNamesArray[indexPath.row];
    Class class = NSClassFromString(className);
    if (class)
    {
        UIViewController *vc = class.new;
        vc.title = self.titlesArray[indexPath.row];
        
        //[[self getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }
    
    /*! 点击立刻取消该cell的选中状态 */
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 获取ViewModel模型
    //BAHomeViewModel *subViewFrame = self.statusFrames[indexPath.row];
    return 10;
}
 
#pragma mark - ***** 解决tableview的分割线短一截
- (void)viewDidLayoutSubviews
{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
    {
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
    {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}
 
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    
    /*! 第一种:3d xyz三维坐标刚出现0.1 0.1 1  0.5 s后正常 */
//    cell.layer.transform = CATransform3DMakeScale(0.1,0.1,1);
//    [UIView animateWithDuration:0.6 animations:^{
//        
//        cell.layer.transform = CATransform3DMakeScale(1,1,1);
//        
//    }];
    
    /*! 第二种:卡片式动画 */
    static CGFloat initialDelay = 0.2f;
    static CGFloat stutter = 0.06f;
    
    cell.contentView.transform =  CGAffineTransformMakeTranslation(SCREEN_WIDTH, 0);
    
    [UIView animateWithDuration:1.0f delay:initialDelay + ((indexPath.row) * stutter) usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
        cell.contentView.transform = CGAffineTransformIdentity;
    } completion:NULL];
    
    /*! 第三种:从下往上 */
    
//    [UIView animateWithDuration:1 animations:^{
//        
//        cell.layer.transform = CATransform3DMakeTranslation(0, 0, 0);
//        
//    }];
    
    /*! 第四种:右下角出来 */
    
//    cell.layer.transform = CATransform3DMakeTranslation(SCREEN_WIDTH, SCREEN_HEIGHT, 0);
//    
//    [UIView animateWithDuration:0.5 animations:^{
//        
//        cell.layer.transform = CATransform3DMakeTranslation(0, 0, 0);
//        
//    }];
    
     /*! 第五种:右上角出现 */
    
//    cell.layer.transform = CATransform3DMakeTranslation(SCREEN_WIDTH, -SCREEN_HEIGHT, 0);
 
    /*! 第六种:翻转动画 */
//    CATransform3D rotation;
//    rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
//    rotation.m44 = 1.0/ -600;
//    //阴影
//    cell.layer.shadowColor = [[UIColor blackColor]CGColor];
//    
//    //阴影偏移
//    cell.layer.shadowOffset = CGSizeMake(10, 10);
//    cell.alpha = 0;
//    cell.layer.transform = rotation;
//    //锚点
//    cell.layer.anchorPoint = CGPointMake(0.5, 0.5);
//    [UIView beginAnimations:@"rotation" context:NULL];
//    [UIView setAnimationDuration:0.8];
//    cell.layer.transform = CATransform3DIdentity;
//    cell.alpha = 1;
//    cell.layer.shadowOffset = CGSizeMake(0, 0);
//    [UIView commitAnimations];
 
    /*! 第七种:扇形动画 */
//    NSArray *array = tableView.indexPathsForVisibleRows;
//    
//    NSIndexPath *firstIndexPath = array[0];
//    //设置anchorPoint
//    cell.layer.anchorPoint = CGPointMake(0, 0.5);
//    
//    //为了防止cell视图移动,重新把cell放回原来的位置
//    cell.layer.position = CGPointMake(0, cell.layer.position.y);
//     //设置cell 按照z轴旋转90度,注意是弧度
//    if (firstIndexPath.row < indexPath.row)
//    {
//        cell.layer.transform = CATransform3DMakeRotation(M_PI_2, 0, 0, 1.0);
//    }
//    else
//    {
//        cell.layer.transform = CATransform3DMakeRotation(- M_PI_2, 0, 0, 1.0);
//    }
//    cell.alpha = 0.0;
//    [UIView animateWithDuration:1 animations:^{
//        
//        cell.layer.transform = CATransform3DIdentity;
//        
//        cell.alpha = 1.0;
//        
//    }];
}
 
@end