【无限互联】ios开发阅读器APP的开发
这个阅读器是仿照网易云阅读做的,读者通过此应用可以阅读最新的新闻,或者自己订阅喜爱网站的RSS,获取最新的资讯,还可以在网上
城找到自己喜爱的书籍和漫画进行在线阅读,也可以下载到本地,以便平时的离线阅读。
主要功能:书籍的本地浏览。
订阅RSS源,获取最新资讯。
阅读新闻。
查看热门书籍。
功能介绍:整体框架
这四个界面都采用MVC的架构模式,用到了网络请求的AFNetWorking框架,并且自己进行了封装,方便自己使用。解析XML的KissXML框架,还用到下拉刷新框架
EGORefreshTableHeaderView,工具类自己扩展了UIView,NSString ,使其方便布局和
方便使用网络请求数据中时间的显示。
自定义标签控制器,将按钮后的视图进行封装,其继承于UIView,
[objc] view plaincopy
1. - (id)initWithFrame:(CGRect)frame
2. imageName:(NSString *)name
3. title:(NSString *)title
4. isSelect:(BOOL)isSelect
5. {
6. self = [super initWithFrame:frame ];
7. if (self) {
8.
9. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake
((frame.size.width-20)/2, 5, 20, 20)];
10.
11. imgView.contentMode = UIViewContentModeScaleAsp ectFit; 12. imgView.image = [UIImage imageNamed :name]; 13. [self addSubview:imgView];
14.
15. //2.创建标题视图
16.
17. CGFloat maxY = CGRectGetMaxY(imgView.frame ); 18. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, m
axY, frame.size.width, 20)];
19. titleLabel.text = title ;
20. titleLabel.backgroundColor = [UIColor clear Color]; 21. titleLabel.textAlignment = NSTextAlignment Center; 22.
23. if (isSelect) {
24. titleLabel.textColor = [UIColor redCo lor]; 25.
26. }
27. else
28. {
29. titleLabel.textColor = [UIColor grayC olor]; 30. }
31. titleLabel.font = [UIFont systemFontOfSiz e:11.0]; 32. [self addSubview:titleLabel ];
33.
34. }
35. return self;
36. }
创建标签栏:
[objc] view plaincopy
1. - (void)_createTabbarVi ew
2. {
3. for (UIView *view in self.tabBar.subviews) 4. {
5. Class cls = NSClassFromString(@"UITabBarBu tton"); 6. if ([view isKindOfClass:cls])
7. {
8. [view removeFromSuperview ]; 9. }
10. }
11.
12. // 创建选中图片的视图
13.
14.
15.
16. NSArray *imgsName_1 = @[@"home_shouye_nor mal", 17. @"home_faxian_normal" , 18. @"home_yueduquan_norma l", 19. @"home_info_norma l" 20. ];
21.
22.
23.
24. NSArray *imgsName_2 = @[@"home_shouye_highLigh ted", 25. @"home_faxian_highLigh ted", 26. @"home_yueduquan_highLighte d", 27. @"home_info_highLighte d" 28. ];
29.
30. NSArray *titles = @[@"我的阅读" ,
31. @"发现",
32. @"阅读圈",
33. @"账号",
34. ];
35.
36.
37. CGFloat itemWidth = kScreenWidth/4.0;
38. CGFloat itemheight = CGRectGetHeight(self.tabBa r.frame);
39.
40. _selectImgs_1 = [NSMutableArray array ]; 41. _selectImgs_2 = [NSMutableArray array ]; 42.
43. for (int i = 0 ; i < 4; i++)
44. {
45. CGRect frame = CGRectMake(i*itemWidth, 0, itemWidth, itemh eight);
46.
47. NSString *imgName_1 = imgsName_1 [i]; 48. NSString *imgName_2 = imgsName_2 [i]; 49.
50. NSString *title = titles[i];
51.
52. SelectedView *selectView_1 = [[SelectedView alloc]initWithFrame:fram
e imageName:imgName_1 title:title isSel ect:NO]; 53.
54. SelectedView *selectView_2 = [[SelectedView alloc]initWithFrame:fram
e imageName:imgName_2 title:title isSelect :YES]; 55.
56. selectView_2.hidden = YES ;
57. [_selectImgs_1 addObject:selectView _1]; 58. [_selectImgs_2 addObject:selectView _2]; 59.
60. [self.tabBar addSubview:selectView _1]; 61. [self.tabBar addSubview:selectView _2]; 62.
63. UIButton *button = [UIButton buttonWithType:UIButtonTy peCustom];
64.
65. button.frame = frame ;
66. button.tag = i;
67.
68. [button addTarget:self action:@selector(clickItem:) forControlEvents
:UIControlEventTouchUpInsi de];
69.
70. [self.tabBar addSubview:butto n]; 71. }
72.
73. [_selectImgs_1[0] setHidden:YES ]; 74. [_selectImgs_2[0] setHidden:NO ];
75.
76.
77.
78.
79. }
用标签上Button的点击事件来控制button下面视图的隐藏与显示。
在“我的阅读”中,又分为“书架”,“订阅”,“杂志”,“推荐”,四个子模块。这四个子模块
的切换可以通过点击导航栏的按钮或者直接向左向右来切换视图,切换过程中视图相连,能
给用户良好的体验,其中具体的实现是在一个控制器中创建滑动视图,将四个子控制器放到
这个控制器中,
左滑右滑时切换控制器:
[objc] view plaincopy
1. - (void)setupTargetViewController:(UIViewController *)targetViewController w
ithSlideType:(XHSlideType)slide Type {
2. if (!targetViewController )
3. return;
4.
5. [self addChildViewController:targetViewContr oller]; 6. CGRect targetViewFrame = targetViewController .view.frame; 7. switch (slideType) {
8. case XHSlideTypeLeft : {
9. targetViewFrame.origin.x = -CGRectGetWidth(self.view.bound s); 10. break;
11. }
12. case XHSlideTypeRight : {
13. targetViewFrame.origin.x = CGRectGetWidth(self.view.bounds) * 2;
14. break;
15. }
16. default:
17. break;
18. }
19. targetViewController.view.frame = targetView Frame; 20. [self.view insertSubview:targetViewController.view atInd ex:0]; 21. [targetViewController didMoveToParentViewContro ller:self]; 22. }
在 “书架”模块中,先做一个可以左右滑动的书架,这样可以放更多的书籍,书籍的内
容和书籍封面都存在本地,点击书籍封面后进入到阅读书籍的界面,书籍的页数根据书籍的
总长度除以每一页的长度计算,翻页时让文本内容偏移,在第一页向上翻页和最后一样向下
翻页时给出提示。
“订阅”的模块显示用户订阅的RSS源,URL地址也存在本地,因为返回数据是XML
,用到了KIssXML解析,可以做一个数据库来分类储存RSS源,便于用户查找和添加自己喜爱的网站。这个界面的标题在用户长按后可以自由调整,点击后弹出资讯的摘要列
,点击单元格后进入到相应的网页。
在“阅读圈”模块中,也分为两个界面:“关注”和“广场”,“广场”模块又分为“热门书籍”和“热门资讯”;
“关注”模块中加载的是最新的新闻,界面可以下拉刷新,头视图可以左右滑动,点击单元格跳转到对应的网页显示新闻详情。
“热门书籍”模块中加载的是最新的图书信息,点击单元格跳转到书籍的详情界面。
总结
这个项目还有很多未做完的模块,比如图书的下载,因为数据请求有问题,所以没有做,还有没有做数据库,导致订阅的界面没做,用户不能搜索订阅自己的资讯。在新闻的阅读界面也应该有评论和分享功能。
没有做完的原因主要是时间分配不合理,有些地方卡住了耗的时间太多。所以开始做的时候应该有个规划。
通过做这个项目,学到了很多东西,比如要善于利用第三方框架,这样可以事半功倍,还要多看别人写的代码,从中能得到一些启发。