Skip to content

XHNewsFramework框架文档

Jack edited this page May 24, 2014 · 9 revisions

XHNewsFramework虽然现在没有那么强大,但是也是我呕心沥血的写作,希望大家能一起理清楚思路,功能维护下去。

这里分了两大模块,

模块一、主页分栏显#示管理框架,主要是现实思路:

1)、ViewController管理---scrollView

2)、scrollView作为横向滑动的基本容器

3)、利用OC的重用机制,达到保持scrollView内部只存在三个内容视图的对象

4)、利用KVO观察scrollView的contentOffset属性,为了同步分栏标题的指示器位置

5)、利用scrollView的特性实现横向快速滑动和停止滑动的功能

模块一对应的类名是XHNewsContainerViewController。

主要功能大概只有这些了,下面对头文件的api接口进行一一的说明。

大家具体看XHNewsContainerViewController.h头文件

该类有具体的属性有以下几个:
我分了几类propertys

一、UI修改的

1、在主页的顶部横向滚动分栏标题的UI(顶部部分)

// 顶部横向滚动视图是否显示出来 @property (nonatomic, assign) BOOL isShowTopScrollToolBar; // default is YES

// 顶部横向滚动视图的背景图
@property (nonatomic, strong) UIImage *topScrollViewToolBarBackgroundImage; // default is nil

// 顶部横向滚动视图的背景颜色
@property (nonatomic, strong) UIColor *topScrollViewToolBarBackgroundColor; // default is [UIColor colorWithWhite:0.902 alpha:1.000]

// 最右边的按钮背景图
@property (nonatomic, strong) UIImage *managerButtonBackgroundImage; // default is arrow image

// 指示器的颜色
@property (nonatomic, strong) UIColor *indicatorColor; // default is redColor

// 顶部横向滚动视图的高度
@property (nonatomic, assign) CGFloat topScrollViewToolBarHieght; // default is 36

// 左边的阴影图片
@property (nonatomic, strong) UIImage *leftShadowImage;

// 右边的阴影图片
@property (nonatomic, strong) UIImage *rightShadowImage;

2、(中间部分)

// 当内容视图快速滑动的时候,我们会看到一个logo的图片,这个就是设置中间内容页的背景logo图
@property (nonatomic, strong) UIImage *midContentLogoImage; // default is netEase logo

// 中间横向滚动的scrollView背景颜色
@property (nonatomic, strong) UIColor *contentScrollViewBackgroundColor; // default is [UIColor whiteColor]

// 是中间内容视图之间的间隔大小,默认是0,意思就是紧紧相连的
@property (nonatomic, assign) CGFloat contentViewPaddingX; // default is 0

// 中间视图的TableView在iOS6 7上适配的问题,所以这里公开设置,默认值是0,修复了iOS6 7的bug。

@property (nonatomic, assign) CGFloat contentViewContentInsetTop; // default is 0

// 获取中间滚动视图的frame

  • (CGRect)scrollViewFrame;

// 获取中间内容视图的frame

  • (CGSize)contentViewSize;

// 这个是为了手动设置跳转页面,这个index必须是现有页面的个数之内,比如我有10个分栏,那你设置index为10,那就会crash了,因为框架内容根本就不存在第11个视图存在,这些错误千万别再犯了。

  • (void)goToContentView:(NSInteger)index;

二、数据源的

// 获取当前可视的内容视图的标记,顺序的 0 1 2 3 4 5 6....
@property (nonatomic, assign) int currentPage;

// 同上的意思,感觉是多余的,我再删除吧!
@property (nonatomic, assign) int lastDisplayedPage;

// 这个是包括XHItem对象元素的已订阅的分栏数据源
@property (nonatomic, strong) NSArray *items;

// 这个相反,括XHItem对象元素的未订阅的分栏数据源,这个主要是为了在重新调整已经订阅与未订阅的管理而需要的
@property (nonatomic, strong) NSArray *unItems;

// 获取在主页上可用的内容视图个数

  • (NSInteger)numberOfVisibleContentViews;

// 获取在主页上总共有多少个内容视图

  • (NSInteger)numberOfContentViews;

// 刷新数据源,当你重新设置items后,就调用这个函数

  • (void)reloadDataSource;

三、重用机制的

// 类似TableView的用法

  • (XHContentView )dequeueReusablePageWithIdentifier:(NSString)identifier;

// 通过index标识来获取具体的内容视图

  • (XHContentView *) contentViewForPage:(NSInteger)page;

// 新需求,当滚动视图停止后,告之最终显示页面的Index

  • (void)didDisplayContentViewAtCurrentPageIndex:(NSInteger)currentPageIndex;

模块二、独立的左右侧滑展示框架

该框架对应的类名是RESideMenu.
大家看到头文件有以下几个属性:(我会描述一些大家常用的修改样式属性,其他不再一一说明,因为有源码在里面的了)

一、修改UI的

// 修改侧滑的动画
@property (assign, readwrite, nonatomic) NSTimeInterval animationDuration;

// 修改侧滑框架的背景
@property (strong, readwrite, nonatomic) UIImage *backgroundImage;

// 侧滑的时候,是否缩放中间的View
@property (assign, readwrite, nonatomic) BOOL scaleContentView;

// 侧滑的时候,是否缩放side的背景图
@property (assign, readwrite, nonatomic) BOOL scaleBackgroundImageView;

// 侧滑的时候,是否缩放左右两边的视图
@property (assign, readwrite, nonatomic) BOOL scaleMenuViewContainer;

// 是否具有视觉差的效果
@property (assign, readwrite, nonatomic) BOOL parallaxEnabled;

// 设置中间视图的缩放系数,0 至 1.0
@property (assign, readwrite, nonatomic) CGFloat contentViewScaleValue;

// 设置横屏的时候,中间视图侧滑的偏移量
@property (assign, readwrite, nonatomic) CGFloat contentViewInLandscapeOffsetCenterX;

// 设置竖屏的时候,中间视图侧滑的偏移量
@property (assign, readwrite, nonatomic) CGFloat contentViewInPortraitOffsetCenterX;

二、框架触发设置的

// 我们经常会需要在特定的页面上不触发侧滑的效果,这个就是打开和关闭side框架的侧滑属性,
@property (assign, readwrite, nonatomic) BOOL panGestureEnabled;

// 在iOS7里面,UINavigationController本身有一个边界侧滑的效果,这里提供统一设置
@property (assign, readwrite, nonatomic) BOOL interactivePopGestureRecognizerEnabled;

// 静态栏的样式
@property (assign, readwrite, nonatomic) UIStatusBarStyle menuPreferredStatusBarStyle;

// 静态栏的隐藏和显示
@property (assign, readwrite, nonatomic) BOOL menuPrefersStatusBarHidden;

三、基本方法使用

// 初始化方法

  • (id)initWithContentViewController:(UIViewController *)contentViewController menuViewController:(UIViewController *)menuViewController;

// 切换不同的contentViewController的方法

  • (void)setContentViewController:(UIViewController *)contentViewController animated:(BOOL)animated;

// 侧滑出左边的Menu视图

  • (void)presentMenuViewController;

// 关闭侧滑,包括侧滑左右两边的都统一用这个方法关闭

  • (void)hideMenuViewController;

// 侧滑出右边的Menu视图

  • (void)presentRightViewController;

// 接收外界传递过来的panGesture手势的方法

  • (void)panGestureRecognized:(UIPanGestureRecognizer *)recognizer;

四、delegate的通知

// 大家看英文都能懂了,不能懂的就说明你还不懂ViewController的执行流程,这个我就不再解释了,自己google吧!

  • (void)sideMenu:(RESideMenu *)sideMenu didRecognizePanGesture:(UIPanGestureRecognizer *)recognizer;
  • (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController;
  • (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController;
  • (void)sideMenu:(RESideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController;
  • (void)sideMenu:(RESideMenu *)sideMenu didHideMenuViewController:(UIViewController *)menuViewController;