测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
Released最后发布 | 2016 年 9 月 |
由 BluePan 维护。
依赖 | |
TAPageControl | >= 0 |
SDWebImage | >= 0 |
这个分类使得向您的滚动视图添加视差头部视图变得非常简单。其他替代方案依赖于对 UIScrollView
、UITableViewController
或 UITableView
的子类化。相反,APParallaxHeader 使用 Objective-C 运行时向 UIScrollView
添加以下两种方法,而无需进行任何子类化。
- (void)addParallaxWithImage:(UIImage *)image andHeight:(CGFloat)height andShadow:(BOOL)shadow;
- (void)addParallaxWithImage:(UIImage *)image andHeight:(CGFloat)height;
- (void)addParallaxWithView:(UIView*)view andHeight:(CGFloat)height;
注意:如果您的项目没有使用 ARC:您必须在 Target Settings > Build Phases > Compile Sources 中将 -fobjc-arc
编译器标志添加到 UIScrollView+ APParallaxHeader.m
。
APParallaxHeader/APParallaxHeader
文件夹拖到您的项目中。UIScrollView+APParallaxHeader.h
导入到需要的位置。(见 /Demo
中的样本 Xcode 项目)
[tableView addParallaxWithImage:[UIImage imageNamed:@"ImageName"] andHeight:160];
注意:添加自定义视图时,请使用 APParallaxViewDelegate
、自动布局约束或 contentMode
来在滚动期间调整自定义视图的大小。
UIView *customView = [[UIView alloc] init];
[customView setFrame:CGRectMake(0, 0, 320, 160)];
[self.tableView addParallaxWithView:customView andHeight:160];
[self.tableView.parallaxView setDelegate:self];
APParallaxViewDelegate 会通知代理关于视差视图大小的变化。
- (void)parallaxView:(APParallaxView *)view willChangeFrame:(CGRect)frame
- (void)parallaxView:(APParallaxView *)view didChangeFrame:(CGRect)frame
UITableViewStylePlain
的表视图标题在滚动时无法按预期固定。0.1.6
0.1.5
APParallaxViewDelegate
)。0.1.4
0.1.3
0.1.2
APParallaxHeader 是由 Mathias Amnell 在 Apping AB 推出。代码灵感来自 Sam Vermette 通过 Sam Vermette's 和 SVPullToRefresh(特别是使用 objc/runtime.h
以非常容易的方式实现,无需子类化)。
APParallaxHeader 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。