码迷,mamicode.com
首页 > 其他好文 > 详细

AutoHome项目的学习

时间:2016-03-30 19:27:04      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

1.自定义UITabBar

 1 #import <UIKit/UIKit.h>
 2 
 3 @interface XHQTabBarViewController : UITabBarController
 4 @property(nonatomic,strong) NSMutableArray * controllers
 5 ;
 6 
 7 //@tip  创建tabbaritem
 8 //@para title tabbaritem标题
 9 //      normal 正常情况下tabbaritem图片
10 //      selectedImage 选中情况下tabbaritem图片
11 //      controllerName tabbaritem所对应的的控制器
12 //@result  无
13 -(void) addItem:(NSString*)title normalImage:(UIImage*)normal highLightImage:(UIImage*)selectedImage controller:(NSString*)controllerName ;
 1 #import "XHQTabBarViewController.h"
 2 
 3 @interface XHQTabBarViewController ()
 4 
 5 @end
 6 
 7 @implementation XHQTabBarViewController
 8 
 9 //初始化
10 -(instancetype)init{
11     if (self=[super init]) {
12         _controllers = [[NSMutableArray alloc] init];
13     }
14     return self;
15 }
16 
17 //创建tabbaritem
18 -(void) addItem:(NSString*)title normalImage:(UIImage*)normal highLightImage:(UIImage*)highLight controller:(NSString*)controllerName {
19     
20     //创建tabBarItem
21     normal = [normal imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
22     highLight = [highLight imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
23     UITabBarItem * item = [[UITabBarItem alloc] initWithTitle:title image:normal selectedImage:highLight];
24     [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName: [UIFont systemFontOfSize:15]} forState:UIControlStateNormal];
25     
26     //得到控制器类
27     Class controllerClass = NSClassFromString(controllerName);
28     
29     //创建控制器
30     UIViewController *  controller = [[controllerClass alloc] init];
31     controller.navigationItem.title = title;//设置导航栏标题
32     
33     //创建导航栏
34     UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
35     
36     //设置item
37     controller.tabBarItem = item;
38     //    controller.tabBarController.tabBar.barTintColor = ;
39     self.tabBar.barTintColor =[UIColor colorWithRed:121.0/255 green:200.0/255 blue:231.0/255 alpha:1];
40     
41     //将控制器加入数组
42     [_controllers addObject:navigationController];
43     
44 }
45 @end

 

 

2.设置cell的动画:

//cell添加动画

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

    //设置Cell的动画效果为3D效果

    //设置xy的初始值为0.1

    cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);

    //xy的最终值为1

    [UIView animateWithDuration:1 animations:^{

        cell.layer.transform = CATransform3DMakeScale(1, 1, 1);

        

    }];

}

 

3.表视图设置索引:

1 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
2 {
3     NSArray *array = @[@"A", @"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z"];
4     self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];//背景色
5     self.tableView.sectionIndexColor = [UIColor blueColor];//字体色
6     return array;
7 }
1 //索引点击事件
2 -(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
3    
4     NSLog(@"点击了第%ld个",index);
5     return 20;
6 }

 

4.UICollectionView的头尾视图设置:

1 #pragma mark 设置头尾视图的大小
2 
3 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
4 {
5     return CGSizeMake(XHQ_SCRWIDTH, 50);
6 }
 1 #pragma mark 返回头尾视图
 2 
 3 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
 4 {
 5    UICollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"HEADER" forIndexPath:indexPath];
 6     
 7   for(UIView *subview in reusableView.subviews)
 8   {
 9       [subview removeFromSuperview];
10   }
11     
12  
13     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, XHQ_SCRWIDTH, 50)];
14     
15     XHQFoundCarSubModel *model = self.dataSource[indexPath.section];
16     
17     label.text = model.name;
18     
19     [reusableView addSubview:label];
20   
21    
22     return reusableView;
23     
24 }

 

5.设置push动画:

//定位按钮被点击
- (void)Localself
{
    XHQFoundMoreViewController *more = [[XHQFoundMoreViewController alloc]init];

//push带动画
    [self pushNextWithType:@"suckEffect" Subtype:@"fromLeft" Viewcontroller:more];
}

 

 1 - (void)pushNextWithType:(NSString *)type Subtype:(NSString *)subtype Viewcontroller:(UIViewController *)viewController
 2 {
 3     CATransition *transition = [CATransition animation];
 4     transition.type = type;
 5     transition.subtype = subtype;
 6     transition.duration = 1;
 7     viewController.hidesBottomBarWhenPushed = YES;
 8     [self.navigationController .view.layer addAnimation:transition forKey:nil];
 9     [self.navigationController pushViewController:viewController animated:nil];
10 
11 }

 

6.封装图形的圆角设置:

1 + (void)layerCornerRadius:(CALayer *)dest radius:(float)radius width:(float)width color:(UIColor *)color
2 {
3     dest.cornerRadius = radius;
4     dest.borderWidth = width;
5     dest.borderColor = color.CGColor;
6     dest.masksToBounds = YES;
7 }
类方法调用:

1
[XHQAuxiliary layerCornerRadius:self.userface.layer radius:30 width:0 color:[UIColor yellowColor]];

 

7.实现夜间模式的开关按钮:

1 if(indexPath.row == 2)
2         {
3             UISwitch *swi = [[UISwitch alloc]init];
4             [swi addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];
5             cell.accessoryView = swi;
6         }

 

8.实现图头放大:

 1 #pragma mark - 实现scrollView的代理方法
 2 -(void)scrollViewDidScroll:(UIScrollView *)scrollView
 3 {
 4     //实现图头放大的核心思想:通过改变scrollView的偏移量来改变图片的frame
 5   if(scrollView == self.tableView)
 6   {
 7         //获取scrollView的偏移量
 8         float yOffset = scrollView.contentOffset.y;
 9       
10       
11         NSLog(@"yoffset = %f",yOffset);  //往下拉值越来越小
12       
13         //scrollView的横向偏移量是随着纵向偏移量的变化而变化
14         float xOffset = (yOffset + ImageOriginHeight) / 2;
15         if (yOffset < -ImageOriginHeight) {
16             //改变imageView的frame
17             CGRect rect = _headerImageView.frame;
18            
19             rect.origin.y = -yOffset;
20             rect.size.height = -yOffset * 2;
21             
22             rect.origin.x = xOffset;
23             rect.size.width = XHQ_SCRWIDTH + fabs(xOffset) * 2;
24            
25             _headerImageView.frame = rect;
26          //   NSLog(@"%f??%f",rect.origin.y, rect.size.height);
27        
28     }
29      // NSLog(@"%f",yOffset);
30   }
31 }

 

9.实现夜间模式效果:

 1 - (void)changeValue:(UISwitch *)swi
 2 {
 3     if (swi.on) {
 4         //添加半透明view到window上
 5         UIApplication * app = [UIApplication sharedApplication];
 6         AppDelegate *delegate = (AppDelegate *) app.delegate;
 7         _darkView = [[UIView alloc]initWithFrame:self.view.frame];
 8         //设置view的背景色
 9         _darkView.backgroundColor = [UIColor blackColor];
10         _darkView.alpha = 0.3;
11         //关闭view的用户交互(响应者链)
12         _darkView.userInteractionEnabled = NO;
13         [delegate.window addSubview:_darkView];
14         
15     }
16     else
17     {
18         [_darkView removeFromSuperview];
19     }
20 
21 }

 

10.清除缓存实现:

 1 - (float ) folderSizeAtPath:(NSString*) folderPath
 2 {
 3     NSFileManager* manager = [NSFileManager defaultManager];
 4     if (![manager fileExistsAtPath:folderPath]) return 0;
 5     NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
 6     NSString* fileName;
 7     long long folderSize = 0;
 8     while ((fileName = [childFilesEnumerator nextObject]) != nil){
 9         NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
10         folderSize += [self fileSizeAtPath:fileAbsolutePath];
11     }
12     return folderSize/(1024.0*1024.0);
13 }
 1 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
 2             NSString *path = [paths lastObject];
 3             
 4             NSString *str = [NSString stringWithFormat:@"缓存已清除%.1fM", [self folderSizeAtPath:path]];
 5             
 6             NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:path];
 7             for (NSString *p in files) {
 8                 NSError *error;
 9                 NSString *Path = [path stringByAppendingPathComponent:p];
10                 if ([[NSFileManager defaultManager] fileExistsAtPath:Path]) {
11                     [[NSFileManager defaultManager] removeItemAtPath:Path error:&error];
12                 }
13             }
14             

 

11.退出程序:

1 RESideMenuItem * item3 = [[RESideMenuItem alloc]initWithTitle:@"退出" action:^(RESideMenu *menu, RESideMenuItem *item) {
2              exit(0);
3           
4         }];

 

看了别人的一个项目,只想说写的超级好呀,这逻辑,这封装......学习学习!!!

 

AutoHome项目的学习

标签:

原文地址:http://www.cnblogs.com/pengsi/p/5337300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!