视图控制器 支持滑动点击
来源:互联网 发布:单片机跑马灯实验报告 编辑:程序博客网 时间:2024/05/21 06:44
[self addSegement];
UICollectionViewFlowLayout *picture_V = [[UICollectionViewFlowLayout alloc] init];//最小行间距picture_V.minimumLineSpacing = 0 ;//滚动方向picture_V.scrollDirection = UICollectionViewScrollDirectionHorizontal;//单位大小picture_V.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width , [UIScreen mainScreen].bounds.size.height - 64 );//与屏幕四边的间距picture_V.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0 , 35 * ScreenHeigth , [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 60) collectionViewLayout:picture_V];self.collectionV.dataSource = self;self.collectionV.delegate = self;// self.collectionV.contentOffset = CGPointMake(375, 200);self.collectionV.pagingEnabled = YES;//设置点击状态栏不会顶部self.collectionV.scrollsToTop = NO;self.collectionV.showsHorizontalScrollIndicator = YES;self.collectionV.backgroundColor = [UIColor clearColor];[self.view addSubview:self.collectionV];[self.collectionV registerClass:[NEWSCollectionViewCell class] forCellWithReuseIdentifier:@"news"];[self.collectionV registerClass:[HOTCollectionViewCell class] forCellWithReuseIdentifier:@"hot"];[self.collectionV registerClass:[CategoryCollectionViewCell class] forCellWithReuseIdentifier:@"category"];//滑条self.scrollView = [[UIView alloc] initWithFrame:CGRectMake(75 * ScreenWidth, 33 * ScreenHeigth, 75 * ScreenWidth, 2 * ScreenHeigth)];self.scrollView.backgroundColor = [UIColor colorWithRed:240 / 255.0 green:134 / 255.0 blue:12 / 255.0 alpha:1.0];[self.view addSubview:self.scrollView];
//添加喜欢分类
- (void)addSegement
{
UIView view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width , 35 ScreenHeigth )];
view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:view];
self.segmentedC = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"动态", @"热门", @"分类", nil]];self.segmentedC.frame = CGRectMake(75 * ScreenWidth, 0, [UIScreen mainScreen].bounds.size.width - 75 * ScreenWidth * 2 , 35 * ScreenHeigth );self.segmentedC.selectedSegmentIndex = 0;
pragma 将segmentedControl去掉边框
self.segmentedC.tintColor = [UIColor clearColor];//去掉颜色,现在整个segment都看不见NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16 ], NSForegroundColorAttributeName: [UIColor colorWithRed:240 / 255.0 green:134 / 255.0 blue:12 / 255.0 alpha:1.0]};[self.segmentedC setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置文字属性NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16 ],NSForegroundColorAttributeName: [UIColor lightGrayColor]};[self.segmentedC setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];[self.segmentedC addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];[view addSubview:self.segmentedC];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 3 ;
}
// 点击segment偏移屏幕
- (void)segmentedAction:(UISegmentedControl *)sender
{
self.collectionV.contentOffset = CGPointMake(self.collectionV.frame.size.width * sender.selectedSegmentIndex, 0);[self.collectionV reloadData];//动画滑块 点击改变滑块位置[UIView animateWithDuration:0.2 animations:^{ self.scrollView.frame = CGRectMake(75 *ScreenWidth + (75 *ScreenWidth) * sender.selectedSegmentIndex, 33 * ScreenHeigth, 75 * ScreenWidth, 2 * ScreenHeigth);}];
}
// 滑动屏幕改变segment
- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
self.segmentedC.selectedSegmentIndex = self.collectionV.contentOffset.x / self.collectionV.frame.size.width;//动画滑块 点击改变滑块位置[UIView animateWithDuration:0.2 animations:^{ self.scrollView.frame = CGRectMake(75 * ScreenWidth + (75 * ScreenWidth) * self.collectionV.contentOffset.x / self.collectionV.frame.size.width, 33 * ScreenHeigth, 75 * ScreenWidth, 2 * ScreenHeigth);}];
}
0 0
- 视图控制器 支持滑动点击
- iOS滑动选项卡类型的视图控制器,支持复用
- scrollView滑动切换不同试图控制器的视图
- pageViewController实现多视图(控制器)滑动切换
- iOS -- 点击button实现tabbar视图控制器跳转
- iOS视图控制器编程指南—— 支持无障碍
- 控制器 & 视图
- 视图控制器
- 视图控制器
- 视图控制器
- 视图控制器
- 视图控制器
- 视图控制器
- 视图控制器
- 视图控制器
- 视图控制器
- 视图控制器
- 视图控制器
- uva12118
- Jmeter入门/实例
- C#中DataGridView的数据批量更新
- toj 4614 Infinite Dictionaries
- 【工作记录】爬虫
- 视图控制器 支持滑动点击
- Linux服务管理(1)--服务的分类与启动
- 第三方操作数据库LitePal解读
- 1024客户端
- centos7下使用yum安装mysql
- 如何从优化SQL入手提高数据仓库的ETL效率
- 1075 Thread in a space
- 二叉树------序列化与反序列化二叉树
- toj 4615 Tetrahedrons and Spheres