服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - IOS - iOS项目开发--实现类似淘宝详情页面

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

2021-02-14 23:38小兵快跑 IOS

本篇文章主要介绍了iOS实现类似淘宝详情页面,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

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

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

基本思路:

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

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

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

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

5、demo只提供简单的思路,项目具体实现基本相同
iOS项目开发--实现类似淘宝详情页面

?
1
2
3
4
5
6
7
8
9
10
/** 封装刷新 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"

主要代码

?
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
- (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

?
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
#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解析iOS开发中的FirstResponder第一响应对象

    解析iOS开发中的FirstResponder第一响应对象

    这篇文章主要介绍了解析iOS开发中的FirstResponder第一响应对象,包括View的FirstResponder的释放问题,需要的朋友可以参考下...

    一片枫叶4662020-12-25
  • IOSiOS布局渲染之UIView方法的调用时机详解

    iOS布局渲染之UIView方法的调用时机详解

    在你刚开始开发 iOS 应用时,最难避免或者是调试的就是和布局相关的问题,下面这篇文章主要给大家介绍了关于iOS布局渲染之UIView方法调用时机的相关资料...

    windtersharp7642021-05-04
  • IOS关于iOS自适应cell行高的那些事儿

    关于iOS自适应cell行高的那些事儿

    这篇文章主要给大家介绍了关于iOS自适应cell行高的那些事儿,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的...

    daisy6092021-05-17
  • IOSiOS中tableview 两级cell的展开与收回的示例代码

    iOS中tableview 两级cell的展开与收回的示例代码

    本篇文章主要介绍了iOS中tableview 两级cell的展开与收回的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    J_Kang3862021-04-22
  • IOSiOS通过逆向理解Block的内存模型

    iOS通过逆向理解Block的内存模型

    自从对 iOS 的逆向初窥门径后,我也经常通过它来分析一些比较大的应用,参考一下这些应用中某些功能的实现。这个探索的过程乐趣多多,不仅能满足自...

    Swiftyper12832021-03-03
  • IOSIOS开发之字典转字符串的实例详解

    IOS开发之字典转字符串的实例详解

    这篇文章主要介绍了IOS开发之字典转字符串的实例详解的相关资料,希望通过本文能帮助到大家,让大家掌握这样的方法,需要的朋友可以参考下...

    苦练内功5832021-04-01
  • IOSIOS 屏幕适配方案实现缩放window的示例代码

    IOS 屏幕适配方案实现缩放window的示例代码

    这篇文章主要介绍了IOS 屏幕适配方案实现缩放window的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要...

    xiari5772021-06-01
  • IOSiOS 雷达效果实例详解

    iOS 雷达效果实例详解

    这篇文章主要介绍了iOS 雷达效果实例详解的相关资料,需要的朋友可以参考下...

    SimpleWorld11022021-01-28