iOS基础教程-collectionView的应用

本文介绍了如何使用UICollectionView创建水平滚动的图片展示效果,包括设置布局、注册单元格和视图、实现数据源及代理方法等关键步骤。

相信,部分人用scrollerView做过,或者见过一组图片循环滚动的效果,还有一些,比较多的图片展示页面,这是如果还使用scrollerView的话,那么显然很不合理,比较麻烦,今天,就来介绍一种继承与UIScrollerView的控件,UICollertionView。

 

较简单的用法,后期会作践完善

ViewController.h 中

#import <UIKit/UIKit.h>

 //此时,需要签署三个协议,代理,数据源 和 layout

@interface ViewController : UIViewController<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

 

 

@end

 

//  ViewController.m

//  collection

//

//  Created by Mac on 15-7-23.

//  Copyright (c) 2015年 Mac. All rights reserved.

//

 

#import "ViewController.h"

 

@interface ViewController ()

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    //初始化布局,创建layout,必须设置

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];

//设置内容滑动方向    

    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

 

//设置垂直方向得最小距离

    layout.minimumInteritemSpacing = 10;

    //设置水平方向得最小距离

    layout.minimumLineSpacing = 10;

    //设置四周得边缘距离

    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);

 

 //创建collectionView,并添加layout,必须添加

    UICollectionView *view = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:layout];

    

    [self.view addSubview:view];

    view.backgroundColor = [UIColor redColor];

    

 //签署代理和数据源

    view.delegate = self;

    view.dataSource = self;

    //注册单元格。  注册带xib的cell的方法不同

    [view registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"newTtem"];

    

  //组册组得头视图,可设置,可不设置

        [view registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headView"];

        //组册组得尾视图,可设置,可不设置,若设置,则下面必须返回其大小

        [view registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView"];

}

 注:若要显示组的头尾试图,需要返回layout方法里的头尾试图的大小。此处的头尾试图指的是组的头尾试图。-(CGSize)collection 开头的数据源代理。

//创建组得个数

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 1;

}

//设置单元格的个数,在collectionView称其为item

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    

    return 40;

    

}

//创建item得内容

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"newTtem" forIndexPath:indexPath];

    cell.backgroundColor = [UIColor orangeColor];

    return cell;

}

 

//代理方法事项单元格得大小,单元格显示的大小

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

    return CGSizeMake(50, 50);

}

 

//创建完cell得内容后,仍要设置代理方法,返回头视图,和尾视图

- (UICollectionReusableView*)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{

    if (kind == UICollectionElementKindSectionHeader) {

        

        

UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"headView" forIndexPath:indexPath];

        headerView.backgroundColor = [UIColor purpleColor];

        

        return headerView;

    }

    

    UICollectionReusableView *footer = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"footerView" forIndexPath:indexPath];

    footer.backgroundColor = [UIColor redColor];

    

    return footer;

    

    

}

 

}

#define mark单元格得点击方法

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{    

}

 

//设置初始时距左距离

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

    return UIEdgeInsetsMake(0, 0, 0, 0);

}

 //上面说过collectionView继承与ScrollerView,所以其代理方法也可使用

//设置单元格将要结束拖动时调用

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{

    

}

 

@end

 

转载于:https://www.cnblogs.com/angelfeather/articles/5946688.html

在车辆工程中,悬架系统的性能评估和优化一直是研究的热点。悬架不仅关乎车辆的乘坐舒适性,还直接影响到车辆的操控性和稳定性。为了深入理解悬架的动态行为,研究人员经常使用“二自由度悬架模型”来简化分析,并运用“传递函数”这一数学工具来描述悬架系统的动态特性。 二自由度悬架模型将复杂的车辆系统简化为两个独立的部分:车轮和车身。这种简化模型能够较准确地模拟出车辆在垂直方向上的运动行为,同时忽略了侧向和纵向的动态影响,这使得工程师能够更加专注于分析与优化与垂直动态相关的性能指标。 传递函数作为控制系统理论中的一种工具,能够描述系统输入和输出之间的关系。在悬架系统中,传递函数特别重要,因为它能够反映出路面不平度如何被悬架系统转化为车内乘员感受到的振动。通过传递函数,我们可以得到一个频率域上的表达式,从中分析出悬架系统的关键动态特性,如系统的振幅衰减特性和共振频率等。 在实际应用中,工程师通过使用MATLAB这类数学软件,建立双质量悬架的数学模型。模型中的参数包括车轮质量、车身质量、弹簧刚度以及阻尼系数等。通过编程求解,工程师可以得到悬架系统的传递函数,并据此绘制出传递函数曲线。这为评估悬架性能提供了一个直观的工具,使工程师能够了解悬架在不同频率激励下的响应情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值