iOS项目开发--实现类似淘宝详情页面

 更新时间:2016年11月14日 10:10:27   作者:小兵快跑  
本篇文章主要介绍了iOS实现类似淘宝详情页面,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

前段时间公司在研发一个电商项目,趁现在有时间把其中的知识点整理整理。

项目的商品详情页面当时是仿制淘宝的,用到的第三方库是MJRefresh,上拉操作和下拉操作的刷新效果是把MJRefresh刷新效果从新建个分类封装了一下,感谢杰哥!!!

基本思路:

1、设置一个 UIScrollView 作为视图底层,并且设置分页为两页

2、然后在第一个分页上添加一个 UITableView 并且设置表格能够上提加载(上拉操作即为让视图滚动到下一页)

3、 在第二个分页上添加一个 UIScrollView 并且设置能有下拉刷新操作(下拉操作即为让视图滚动到上一页)

4、第二个分页UIScrollView添加子UIView,一般式商品的图文详情、产品参数、店铺等

5、Demo只提供简单的思路,项目具体实现基本相同

 /** 封装刷新 MJRefresh */
#import "QRG_MJRefreshAutoFooter.h"
#import "QRG_MJRefreshNormalHeader.h"

#import "CollectionViewCell.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

#define ARCCOLOR (arc4random() % 255/256.0)
#import "ViewController.h"

主要代码

- (void)viewDidLoad {
 [super viewDidLoad];

 /** 底层view*/
 UIScrollView *mainScrollView = [[UIScrollView alloc] init];
 mainScrollView.scrollEnabled = NO;
 mainScrollView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
 mainScrollView.contentSize = CGSizeMake(WIDTH, HEIGHT * 2);
 mainScrollView.backgroundColor = [UIColor greenColor];
 mainScrollView.pagingEnabled = YES;
 mainScrollView.bounces = YES;
 [self.view addSubview:mainScrollView];
 /** 第一页面 table*/ 
 OneTable = [[UITableView alloc] init];
 OneTable.frame = CGRectMake(0,0, WIDTH, HEIGHT - 64);
 OneTable.separatorColor = [UIColor greenColor];
 OneTable.delegate = self;
 OneTable.dataSource = self;
 OneTable.rowHeight = 80;
 [mainScrollView addSubview:OneTable];
 /** 第二页面 scrollView*/  
 UIScrollView *TwoScrollView = [[UIScrollView alloc] init];
 TwoScrollView.frame = CGRectMake(0, HEIGHT + 64, WIDTH, HEIGHT - 64);
 TwoScrollView.contentSize = CGSizeMake(WIDTH * 3, HEIGHT - 64);
 TwoScrollView.backgroundColor = [UIColor cyanColor];
 TwoScrollView.pagingEnabled = YES;
 TwoScrollView.bounces = NO;

 [mainScrollView addSubview:TwoScrollView];

 /** 第二页面 table*/ 

 TwoTable = [[UITableView alloc] init];
 TwoTable.frame = CGRectMake(WIDTH, 0, WIDTH, HEIGHT - 64);
 TwoTable.separatorColor = [UIColor redColor];
 TwoTable.delegate = self;
 TwoTable.dataSource = self;
 [TwoScrollView addSubview:TwoTable];

 /** 第二页面 UICollectionView*/ 
 UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
 [flow setScrollDirection:UICollectionViewScrollDirectionVertical];

 UICollectionView *TwoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64) collectionViewLayout:flow];
 TwoCollectionView.backgroundColor = [UIColor lightTextColor];
 TwoCollectionView.delegate = self;
 TwoCollectionView.dataSource = self;
 [TwoScrollView addSubview:TwoCollectionView];

// [TwoCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Coll"];

 [TwoCollectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"Coll"];


 //设置UITableView 上拉加载
 OneTable.mj_footer = [QRG_MJRefreshAutoFooter footerWithRefreshingBlock:^{
  //上拉,执行对应的操作---改变底层滚动视图的滚动到对应位置
  //设置动画效果
  [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
   //   self.scrollV.contentOffset = CGPointMake(0, IPHONE_H);
   [mainScrollView setContentOffset:CGPointMake(0, HEIGHT)];

  } completion:^(BOOL finished) {
   //结束加载
   [OneTable.mj_footer endRefreshing];
  }];


 }];

 //设置TwoCollectionView 有下拉操作
 TwoCollectionView.mj_header = [QRG_MJRefreshNormalHeader headerWithRefreshingBlock:^{
  //下拉执行对应的操作
  //  self.scrollV.contentOffset = CGPointMake(0,0);
  [UIView animateWithDuration:1 animations:^{
   [mainScrollView setContentOffset:CGPointMake(0, - 64)];

  }];

  //结束加载
  [TwoCollectionView.mj_header endRefreshing];
 }];

 //设置TwoTable 有下拉操作
 TwoTable.mj_header = [QRG_MJRefreshNormalHeader headerWithRefreshingBlock:^{
  //下拉执行对应的操作
  //  self.scrollV.contentOffset = CGPointMake(0,0);

  [UIView animateWithDuration:1 animations:^{
   [mainScrollView setContentOffset:CGPointMake(0, - 64)];

  }];  
  //结束加载
  [TwoTable.mj_header endRefreshing];
 }];


}

pragma mark---------Delegate

#pragma mark---------tableDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
 CGFloat height;
  if([tableView isEqual:OneTable])
  {
   height = 80;
  }else
  {
   return 120;
  }
 return height;


}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 static NSString *Cell = @"Cell";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell];

 if(!cell)
 {
  cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
 }

 cell.textLabel.text = [NSString stringWithFormat:@"%ld--askl",indexPath.row];
 cell.imageView.image = [UIImage imageNamed:@"6"];
 return cell;

}

#pragma mark---------CollectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
 return 20;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
 return CGSizeMake(150, 100);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
 static NSString *Coll = @"Coll";

 CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:Coll forIndexPath:indexPath];

// cell.backgroundColor =[UIColor greenColor];
 return cell;
}

 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • iOS应用开发中使用NSLocale类实现对象信息的本地化

    iOS应用开发中使用NSLocale类实现对象信息的本地化

    这篇文章主要介绍了iOS应用开发中使用NSLocale类实现对象信息的本地化的方法,能够将时间和货币等格式化为与系统本地设置相同的偏好,需要的朋友可以参考下
    2016-05-05
  • android中UIColletionView瀑布流布局实现思路以及封装的实现

    android中UIColletionView瀑布流布局实现思路以及封装的实现

    本篇文章主要介绍了android中UIColletionView瀑布流布局实现思路以及封装的实现,具有一定的参考价值,有兴趣的可以了解一下。
    2017-02-02
  • 10个非常实用的iOS小技巧

    10个非常实用的iOS小技巧

    这篇文章主要为大家详细介绍了10个非常实用的iOS小技巧,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-03-03
  • iOS中字符串换行的实现方法

    iOS中字符串换行的实现方法

    大家应该都有所体会,单行字符数过多会影响美观,所以下面这篇文章主要给大家介绍了关于iOS中字符串换行的实现方法,文中通过图文介绍的非常详细,需要的朋友可以参考下
    2018-07-07
  • iOS Gif图片展示N种方式(原生+第三方)

    iOS Gif图片展示N种方式(原生+第三方)

    这篇文章主要介绍了iOS Gif图片展示N种方式,包括原生、第三方方式展示,感兴趣的小伙伴们可以参考一下
    2016-03-03
  • iOS项目开发--实现类似淘宝详情页面

    iOS项目开发--实现类似淘宝详情页面

    本篇文章主要介绍了iOS实现类似淘宝详情页面,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-11-11
  • iOS push侧滑返回功能实现方法

    iOS push侧滑返回功能实现方法

    这篇文章主要为大家详细介绍了iOS push侧滑返回功能实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-05-05
  • iOS中多线程的入门使用教程(Swift)

    iOS中多线程的入门使用教程(Swift)

    这篇文章主要给大家介绍了关于iOS中多线程入门使用的相关资料,一个进程中可以开启多条线程,每条线程可以并行执行不同的任务,本文通过示例代码介绍的非常详细,需要的朋友可以参考下
    2021-11-11
  • iOS中WKWebView白屏问题的分析与解决

    iOS中WKWebView白屏问题的分析与解决

    最近在工作中遇到了WKWebView白屏的问题,所以这篇文章主要给大家介绍了关于iOS中WKWebView白屏问题的分析与解决方法,文中通过示例代码介绍的非常详细,对同样遇到这个问题的朋友具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
    2017-10-10
  • iOS 微信分享功能简单实现

    iOS 微信分享功能简单实现

    本文介绍了iOS 微信分享功能的实现步骤与方法,具有一定的参考作用。下面跟着小编一起来看下吧
    2017-01-01

最新评论