这个阅读器是仿照网易云阅读做的,读者通过此应用可以阅读最新的新闻,或者自己订阅喜爱网站的RSS,获取最新的资讯,还可以在网上书城找到自己喜爱的书籍和漫画进行在线阅读,也可以下载到本地,以便平时的离线阅读。
主要功能:书籍的本地浏览。
订阅RSS源,获取最新资讯。
阅读新闻。
查看热门书籍。
功能介绍:整体框架
这四个界面都采用MVC的架构模式,用到了网络请求的AFNetWorking框架,并且自己进行了封装,方便自己使用。解析XML的KissXML框架,还用到下拉刷新框架EGORefreshTableHeaderView,工具类自己扩展了UIView,NSString ,使其方便布局和方便使用网络请求数据中时间的显示。
自定义标签控制器,将按钮后的视图进行封装,其继承于UIView,
- (id)initWithFrame:(CGRect)frame
imageName:(NSString *)name
title:(NSString *)title
isSelect:(BOOL)isSelect
{
self = [super initWithFrame:frame];
if (self) {
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width-20)/2, 5, 20, 20)];
imgView.contentMode = UIViewContentModeScaleAspectFit;
imgView.image = [UIImage imageNamed:name];
[self addSubview:imgView];
//2.创建标题视图
CGFloat maxY = CGRectGetMaxY(imgView.frame);
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, maxY, frame.size.width, 20)];
titleLabel.text = title;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
if (isSelect) {
titleLabel.textColor = [UIColor redColor];
}
else
{
titleLabel.textColor = [UIColor grayColor];
}
titleLabel.font = [UIFont systemFontOfSize:11.0];
[self addSubview:titleLabel];
}
return self;
}
创建标签栏:
- (void)_createTabbarView
{
for (UIView *view in self.tabBar.subviews)
{
Class cls = NSClassFromString(@"UITabBarButton");
if ([view isKindOfClass:cls])
{
[view removeFromSuperview];
}
}
// 创建选中图片的视图
NSArray *imgsName_1 = @[@"home_shouye_normal",
@"home_faxian_normal",
@"home_yueduquan_normal",
@"home_info_normal"
];
NSArray *imgsName_2 = @[@"home_shouye_highLighted",
@"home_faxian_highLighted",
@"home_yueduquan_highLighted",
@"home_info_highLighted"
];
NSArray *titles = @[@"我的阅读",
@"发现",
@"阅读圈",
@"账号",
];
CGFloat itemWidth = kScreenWidth/4.0;
CGFloat itemheight = CGRectGetHeight(self.tabBar.frame);
_selectImgs_1 = [NSMutableArray array];
_selectImgs_2 = [NSMutableArray array];
for (int i = 0 ; i < 4; i++)
{
CGRect frame = CGRectMake(i*itemWidth, 0, itemWidth, itemheight);
NSString *imgName_1 = imgsName_1[i];
NSString *imgName_2 = imgsName_2[i];
NSString *title = titles[i];
SelectedView *selectView_1 = [[SelectedView alloc]initWithFrame:frame imageName:imgName_1 title:title isSelect:NO];
SelectedView *selectView_2 = [[SelectedView alloc]initWithFrame:frame imageName:imgName_2 title:title isSelect:YES];
selectView_2.hidden = YES;
[_selectImgs_1 addObject:selectView_1];
[_selectImgs_2 addObject:selectView_2];
[self.tabBar addSubview:selectView_1];
[self.tabBar addSubview:selectView_2];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = frame;
button.tag = i;
[button addTarget:self action:@selector(clickItem:) forControlEvents:UIControlEventTouchUpInside];
[self.tabBar addSubview:button];
}
[_selectImgs_1[0] setHidden:YES];
[_selectImgs_2[0] setHidden:NO];
}
用标签上Button的点击事件来控制button下面视图的隐藏与显示。
在“我的阅读”中,又分为“书架”,“订阅”,“杂志”,“推荐”,四个子模块。这四个子模块的切换可以通过点击导航栏的按钮或者直接向左向右来切换视图,切换过程中视图相连,能给用户良好的体验,其中具体的实现是在一个控制器中创建滑动视图,将四个子控制器放到这个控制器中,
左滑右滑时切换控制器:
- (void)setupTargetViewController:(UIViewController *)targetViewController withSlideType:(XHSlideType)slideType {
if (!targetViewController)
return;
[self addChildViewController:targetViewController];
CGRect targetViewFrame = targetViewController.view.frame;
switch (slideType) {
case XHSlideTypeLeft: {
targetViewFrame.origin.x = -CGRectGetWidth(self.view.bounds);
break;
}
case XHSlideTypeRight: {
targetViewFrame.origin.x = CGRectGetWidth(self.view.bounds) * 2;
break;
}
default:
break;
}
targetViewController.view.frame = targetViewFrame;
[self.view insertSubview:targetViewController.view atIndex:0];
[targetViewController didMoveToParentViewController:self];
}
在 “书架” 模块中,先做一个可以左右滑动的书架,这样可以放更多的书籍,书籍的内容和书籍封面都存在本地,点击书籍封面后进入到阅读书籍的界面,书籍的页数根据书籍的总长度除以每一页的长度计算,翻页时让文本内容偏移,在第一页向上翻页和最后一样向下翻页时给出提示。
“订阅”的模块显示用户订阅的RSS源,URL地址也存在本地,因为返回数据是XML格式,用到了KIssXML解析,可以做一个数据库来分类储存RSS源,便于用户查找和添加自己喜爱的网站。这个界面的标题在用户长按后可以自由调整,点击后弹出资讯的摘要列表,点击单元格后进入到相应的网页。
在“阅读圈”模块中,也分为两个界面:“关注”和“广场”,“广场”模块又分为“热门书籍”和“热门资讯”;
“关注”模块中加载的是最新的新闻,界面可以下拉刷新,头视图可以左右滑动,点击单元格跳转到对应的网页显示新闻详情。
“热门书籍”模块中加载的是最新的图书信息,点击单元格跳转到书籍的详情界面。
总结
这个项目还有很多未做完的模块,比如图书的下载,因为数据请求有问题,所以没有做,还有没有做数据库,导致订阅的界面没做,用户不能搜索订阅自己的资讯。在新闻的阅读界面也应该有评论和分享功能。
没有做完的原因主要是时间分配不合理,有些地方卡住了耗的时间太多。所以开始做的时候应该有个规划。
通过做这个项目,学到了很多东西,比如要善于利用第三方框架,这样可以事半功倍,还要多看别人写的代码,从中能得到一些启发。