此类别使您能够轻松添加一个透视式头部视图到您的滚动视图。其他替代方案需要通过继承 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-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)frame0.1.6
0.1.5
APParallaxViewDelegate)。0.1.4
0.1.3
0.1.2
APParallaxHeader 是由 Mathias Amnell 在 Apping AB 创建的。代码灵感来源于 Sam Vermette 的作品 SVPullToRefresh(特别是使用 objc/runtime.h 来实现,无需子类化,使得实现变得非常简单)。
APParallaxHeader 以 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。